How do I link against .tbd files in Xcode 7?

I need to link libz in my project. Normally I would add libz.dylib under the Linked Frameworks and Libraries settings, but now there are only .tbd files and no .dylib files when you search the list of libraries to add. When building I get a "warning: skipping file '/Users/me/xcode7/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/usr/lib/libz.tbd' (unexpected file type 'text' in Frameworks & Libraries build phase)"
Then I build fails with linker errors because of missing symbols. Am I missing something new in the way libraries are linked?

Accepted Answer

This is a known issue in the Xcode 7 beta.


To work around this issue for now, please:

  • Delete all references to .tbd files from either your linked libraries phase, or from the copied bundle resources phase (where they sometimes will be added).
  • Add the library you want to link manually to the "Other Linker Flags" build settings, by adding the argument:

-l<library_name>

for each library you want to link (for example, add "-lsqlite3" (without quotes)).


For those who are curious, the .tbd files are new "text-based stub libraries", that provide a much more compact version of the stub libraries for use in the SDK, and help to significantly reduce its download size.

Answers

the dylib files are still there in /usr/lib (the tbd file seems to be a wrapper of some sort for the dylib files - you can see where they are by reading the tbd file)


Add a library to your project, then click 'Add Other...' then type control-command-G and type in the path '/usr/lib' - you'll find libz.dylib there.


This 'hack' solves my problem.... but I wonder - does XCode 'not support' tbd files fully yet?


EDIT: I'm thinking that maybe OS X El Capitan has support for the file-typ tbd, which is not available with OS X Yosemite? I haven't upgraded my OS yet.

This is a known issue in the Xcode 7 beta.


To work around this issue for now, please:

  • Delete all references to .tbd files from either your linked libraries phase, or from the copied bundle resources phase (where they sometimes will be added).
  • Add the library you want to link manually to the "Other Linker Flags" build settings, by adding the argument:

-l<library_name>

for each library you want to link (for example, add "-lsqlite3" (without quotes)).


For those who are curious, the .tbd files are new "text-based stub libraries", that provide a much more compact version of the stub libraries for use in the SDK, and help to significantly reduce its download size.

For me personally this does not work when trying to add the libz library. It works fine when dealing with sqlite3 but when you do -llibz it fails to build.

That's because to map from the library filename to the value specified in the linker you remove the "lib" prefix and discard the file extension. So libz.a becomes -lz, not -llibz.

This doesn't seem to work for CommonCrypto. I add "-lcommonCrypto" and the build fails with "ld: library not found for -lcommonCrypto". Is there a way to link CommonCrypto using Xcode 7?

I think CommonCrypto is provided by libSystem, so you might need -lSystem or -framework System.

This worked for me only in the simulator, does anyone have a solution for trying to run this code on a device, more importantly an iOS 9 device?

This only works for me when running my app on the simulator, the second I run it on a device it doesnt work

How is this issue still not fixed in Xcode 7 after four betas?

I'm curious in which version of Xcode 7 beta this will be fixed?

I added "-lz" to include the libz.dylib, which I can see is in the /usr/lib folder, but I'm getting the error:


ld: library not found for -lz

I can see a rpath parameter in the Xlinker command in Xcode with the value of '/usr/path'.

Is there another step that is need to configure a project in Xcode to find the libz.dylib ?

btw, I'm using Xcode 7 beta 5.

had the same problem. I found some kind of way around.

  1. Go to Build Phases >Link Binary with Librairies > + > Add other
  2. Once in the file selection window do "CMD"+Shift+G (Go to folder) and type /usr/lib/
  3. From /user/lib you can add : libz.dylib and more...
  4. Compile and have fun

had the same problem. I found some kind of way around.

  1. Go to Build Phases >Link Binary with Librairies > + > Add other
  2. Once in the file selection window do "CMD"+Shift+G (Go to folder) and type /usr/lib/
  3. From /user/lib you can add : libz.dylib and more...
  4. Compile and have fun

This new extension (.tbd) breaks all scripts based on an Xcode install. Am I missing something?

Is it still the recommended way in XCode release ? Version 7.0 (7A220)