Adding .dylibs to XCode's "Link Binary With LIbraries" field

I have a project that needs to link against some dylibs that I can find easily in XCode’s “External LIbraries To Link” search bar, and the project builds without an issue when these libraries are added manually.

The problem I’m running into is that these aren’t frameworks, and adding anything to that line will generate whatever.framework and I can’t find which field in the projucer will save these additions from being nuked every time I save my project from the Projucer.

It was suggested in some other threads that adding -L<complete path to the folder with the dylib> and -l<lib-less name of dylib> to the “extra linker flags” line might work, but I must being doing something wrong there too because I haven’t figured that one out either.

I want to add libcurl.dylib and libz.dylib and a few other libraries from the OS X 10.9 dev tools in the path:
/Applications/Xcode 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/

Does anyone have ideas about how to add these libraries without manually managing the XCode project every time the Projucer saves?

As you have a space in the path ("...Xcode 2...") did you try quoting the path for the -L flag?
-L"/Applications/Xcode 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/"

or even just use -L/usr/lib/ ?

Thank you for the suggestions, it would totally make sense to me that the space could screw things up. However, if that’s it I think there’s got to be a different solution, I just tried with the quotes and it made the project file un-parsable, and escaping the space didn’t work out either. XCode can’t find the libraries using -L/usr/lib/, is this a standard way to access these libraries?

Actually, the Projucer turns these into linker flags so in the Projucer you can list the library paths in the configurations (copy and paste into both Debug and Release):

Then just list the libraries (no ‘lib’ prefix nor .dylib) at the Xcode level:

(I tested this just now, and it links.)

1 Like

Crap, could there be another variable here? I did exactly as you demonstrated and got:

error: /Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lcurl
error: /Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lcurl is not an object file (not allowed in a library)

Other project settings, I’m using are:
– deployment target: OSX 10.8
– target architecture: Universal Binary (32/64-bit)

And then a few c++11 language settings that shouldn’t affect the linker right?

Do you really have libcurl.dylib in /usr/lib?

Sorry for the potential confusion, - I do have libcurl.dylib there. @AmpZ : did you try putting that longer path into the Projucer? (No quotes, as the Projucer quotes them for you.)

But if you’re building for 10.9 then its usr/lib directory should be in the library search path for the build automatically.

Ach, I had a really good feeling about it, but still, same error about -lcurl not being found/not an object file etc. I’ve managed to get static libraries to link in this fashion before, and even w/ this project, but the dylibs still elude me…

What version of XCode are you using? Is there a possibility that different versions used their project files a little differently in a way that this could be broken? I’m on 10.8 and thus am stuck w/ XCode 5.1.1.

Ah, could be. I’m on Xcode 7.