I switched a few days ago from windows and I find a bit confusing the linking process in xcode. I have a static library I want to use called nag C library whose file is "libnagc_nag.a". If I add "/opt/NAG/clmi623dgl/lib/libnagc_nag.a" to "other linker flags", the program runs perfectly. On the other hand, If i go to "Build Phases -> link binary with libraries -> + -> add other" and add "libnagc_nag.a", the library file now appears in the project navigator but I get the following error after the build succeeds and it tries to run it.
dyld: Library not loaded:
/fserver/mo/cl23/CL23.3/CLMI623DG_build/BUILD_mac_64/climp/LIBS/nag_lm/libnagc_nag.dylib
Referenced from: /Users/german/Library/Developer/Xcode/DerivedData/myproj-bjepqyzlzkayspddtaspmmzxgaid/Build/Products/Debug/myproj
Reason: image not found
my questions are:
Why is it any different? does it think it's a dynamic library? How can I solve this problem in the second case?
Edit: I removed a link to the article where I found the answer since it was outdated.
The problem is that the linker flag is the same for both, dynamic and static libraries, and the file extension is removed from it. So, if you have a static and a dynamic library with the same name and only different extensions, the linker will chose by default the dynamic version of the library. This happens even if you chose the the static version in the "link binary with libraries" menu. Then, if the app can't find the dynamic library there will be an error. So, the answers to the question are:
1) it wouldn't make any difference if there wasn't a dynamic library with the same name. 2) The linker only know the name of the library, so by default it choses the dynamic version. 3) The solution can be renaming the library or using the first method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With