I have Core static library, a few Component static libraries that relays on the Core one, and then there is an App that links against both Core and Component libraries. My App can link both against Core and Component as long as Component don’t uses classes from Core (App uses classes from Core).
I got the following error in both armv6 and armv7 versions. So my problem is not the very popular linking issue that everyone has.
ld: symbol(s) not found for architecture armv6
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I added reference to Core in Component and even added it in “Link Binary With Libraries” which shouldn’t be necessary for static lib.
Since I start having this issue I start doubting my design… It probably makes more sense in dynamically linking environment but still it should be doable in static one, especially since this already works under Windows with MSVC compilers.
Edit:
I made some progress! Although I still don’t know where to go with it.
Here is my setup:
-
Core has a class cResourceManager that has a templated method GetResource<T>(int id)
-
Core also has class cResource
-
Component has class cMesh that inherits cResource
Here are some tests:
-
If I try from App to call rm->GetResource<cMesh>(…) I get the linking error
-
If I try from App to construct cMesh I get linking the linking error
-
If I try from App to call static method that will return new instance of cMesh I get the linking error
-
If I comment out the construction of cMesh but leave other member cMesh function calls the App links fine. I can even call delete mesh.
I have never seen anything like it!
If you remove the
cMeshconstructor, then you are then using the default (no argument, no body)cMeshconstructor that is given to you. It almost sounds like there’s a build error or missing code as a result of some code in yourcMeshconstructor and so the library isn’t actually getting generated, and perhaps Xcode isn’t reporting the error. Xcode is no good at reporting linker errors.I would suggest looking at what symbols the linker says are missing and double-check that they are actually defined in your code. My guess is that you’re using one of those symbols in your
cMeshconstructor. A lot of times with virtual base classes, you may forget to define and implement a method or two in a child class. Could be a result of missing a method based on your template, or your template isn’t#included correctly. This could compile fine but result in linker errors like you’re seeing.If Xcode isn’t showing you the full linker error, show the Log Navigator (Command ⌘+7), double-click the last “Build ” entry, select the error, and then press the button on the far-right of the row that appears when selected. The symbols should be listed there. If not, it’s time for
xcodebuildin the Terminal.If it’s not that case, I’d be interested in seeing the results of whether or not the library is being built for the appropriate architecture, or maybe this can spur some progress:
cd ~/Library/Developer/Xcode/DerivedData/proj-<random value>/)rm -r Build)cMeshconstructor present.cd Build/Products/<scheme>-iphoneos)Your compiled static libraries (
<libname>.a) should be in this directory. If they’re not there, they didn’t build (unless you put your products elsewhere). If your libraries are there, let’s confirm that they actually are getting built for the appropriate architecture. Runotool -vh <library>.a. You should see something like:As you can see, my test library was built for ARMv7.