Change Subroutine Names at Build Time to Avoid Collisions in Xcode
<p><strong>BACKGROUND</strong></p>

<p>I'm building an iOS app (which I'll just call <code>MyApp</code> from here) that will rely on calculations done by several separate static libraries (which I'll call <code>Lib1</code>, <code>Lib2</code>, <code>Lib3</code>,...).  Each library is built in it's own project, then imported into a single workspace (so the workspace will contain <code>MyApp</code>, <code>Lib1</code>, <code>Lib2</code>, ...).  More details on how this is set up <a href="https://stackoverflow.com/questions/11655931/xcode-4-3-static-library-generation?rq=1">here</a>.  The libraries are used by other products that are independent from <code>MyApp</code>, so I want to minimize any changes in the libraries.  The libraries are also written in (plain) <code>C</code>, so there are no header files. </p>

<p>Certain function names are used by multiple libraries (so both <code>Lib1</code> and <code>Lib2</code> might each have a <code>DoStuff</code> 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 <code>DoStuff</code> on <code>Lib1</code> might be quite different than the code in <code>DoStuff</code> on <code>Lib2</code>.  It would be very difficult to write one universal <code>DoStuff</code> that would be exactly the same in each library.   </p>

<p><strong>THE ISSUE</strong></p>

<p>While the app is running, it isn't calling the correct <code>DoStuff</code> 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 <code>DoStuff</code> functions).</p>

<p><strong>WHAT I'M LOOKING FOR</strong></p>

<p>Each library has only one entry point from <code>MyApp</code>, and each entry point is uniquely named.  If <code>DoStuff</code> is called from the entry point method of <code>Lib1</code> (or any other method on <code>Lib1</code>, for that matter), then I want it to call the <code>DoStuff</code> method on <code>Lib1</code>.  What's the best way to make that happen?</p>

<p>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 <code>DoStuff</code> method on <code>Lib1</code> could be renamed to <code>Lib1DoStuff</code>, 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.</p>

<hr>

<p><strong>UPDATE</strong></p>

<p>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 <strong><code>THE ISSUE</code></strong> above.  From what I've seen, the <code>objcopy</code> that gets mentioned in a couple of the links in the comments isn't support on iOS.  I eventually came across <a href="https://www.cocoanetics.com/2012/02/xcode-build-rules/" rel="nofollow noreferrer">this</a> blog entry, which talks about creating custom build rules for Xcode targets, and <a href="https://www.objc.io/issues/6-build-tools/build-process/" rel="nofollow noreferrer">this</a> blog that talks about custom build settings and build phases.  </p>

<p><strong>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 <code>WHAT I'M LOOKING FOR</code> section above?</strong>  <strong>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?</strong>  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.</p>

<p>I tried to be as clear as I could, but if there are any questions on what I'm asking please let me know.</p>