BACKGROUND
I'm building an iOS app (which I'll just call MyApp
from here) that will rely on calculations done by several separate static libraries (which I'll call Lib1
, Lib2
, Lib3
,...). Each library is built in it's own project, then imported into a single workspace (so the workspace will contain MyApp
, Lib1
, Lib2
, ...). More details on how this is set up here. The libraries are used by other products that are independent from MyApp
, so I want to minimize any changes in the libraries. The libraries are also written in (plain) C
, so there are no header files.
Certain function names are used by multiple libraries (so both Lib1
and Lib2
might each have a DoStuff
method). Functions with the same name generally do the same thing, but there are some specifics about how that do it that can be different between libraries, so the actual code in DoStuff
on Lib1
might be quite different than the code in DoStuff
on Lib2
. It would be very difficult to write one universal DoStuff
that would be exactly the same in each library.
THE ISSUE
While the app is running, it isn't calling the correct DoStuff
from the correct library. I found out about this because the wrong function was called during a debug session (which eventually caused the app to crash, due to the subtle differences in the DoStuff
functions).
WHAT I'M LOOKING FOR
Each library has only one entry point from MyApp
, and each entry point is uniquely named. If DoStuff
is called from the entry point method of Lib1
(or any other method on Lib1
, for that matter), then I want it to call the DoStuff
method on Lib1
. What's the best way to make that happen?
Is there any way (maybe through a setting somewhere in XCode) I can make it so that each library is it's own namespace? That would be my preferred way to fix the issue. I guess I could go through and rename the duplicate functions so that they are all unique (so the DoStuff
method on Lib1
could be renamed to Lib1DoStuff
, or something similar), but there are hundreds of functions that could have duplicate names, and we are going to be adding hundreds of libraries to the project, so having to go in and rename all the functions by hand and fix all the calls to them would take a significant amount of time, and my boss doesn't see that as a viable option.
UPDATE
After looking at the comments from Josh Caswell and some of the links he provided, it looks like it might be possible to automatically rename all the functions when the libraries are compiled, and that would be the best way to try to fix THE ISSUE
above. From what I've seen, the objcopy
that gets mentioned in a couple of the links in the comments isn't support on iOS. I eventually came across this blog entry, which talks about creating custom build rules for Xcode targets, and this blog that talks about custom build settings and build phases.
Am I right to assume that I can use scripts at some point in the build process to automatically append to the name of all the functions in each of my libraries, instead of doing it manually as I described in the last paragraph of the WHAT I'M LOOKING FOR
section above? If so, which is the correct part of the build process to make those changes? Lastly, what would the syntax look like for doing something like that? The 'scripts' used in the different parts of the build processes certainly doesn't look like Obj-C. I've never used these 'scripts' before, so I'm completely in the dark on how I'd use them, and that's what I'm looking for help with.
I tried to be as clear as I could, but if there are any questions on what I'm asking please let me know.