6

This is driving me crazy, when i try to compile on the simulator, everything is ok, but on the device i got this error:

ld: library not found for -lz
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang failed with exit code 1

Please help me understand the source of the problem:

    Ld /Users/ZConsulting/Library/Developer/Xcode/DerivedData/Fontenay-sous-Bois-dhlecgdgtoldsadoctkyueriyius/Build/Products/Debug-iphoneos/Fontenay-sous-Bois.app/Fontenay-sous-Bois normal armv7
        cd /Users/ZConsulting/Desktop/Fontenay-sous-Bois
        setenv IPHONEOS_DEPLOYMENT_TARGET 5.0
        setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
        /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/ZConsulting/Library/Developer/Xcode/DerivedData/Fontenay-sous-Bois-dhlecgdgtoldsadoctkyueriyius/Build/Products
/Debug-iphoneos -F/Users/ZConsulting/Library/Developer/Xcode/DerivedData/Fontenay-sous-Bois-dhlecgdgtoldsadoctkyueriyius/Build/Products/Debug-iphoneos -F/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
/iPhoneOS5.0.sdk/Developer/Library/Frameworks -filelist /Users/ZConsulting/Library/Developer/Xcode/DerivedData/Fontenay-sous-Bois-dhlecgdgtoldsadoctkyueriyius/Build/Intermediates/Fontenay-sous-Bois.build/Debug-iphoneos/Fontenay-sous-Bois.build/Objects-normal/armv7/Fontenay-sous-Bois.LinkFileList -dead_strip -fobjc-arc -miphoneos-version-min=5.0 -framework SenTestingKit -lz -lz.1.1.3 -framework MobileCoreServices
 -framework SystemConfiguration -framework CFNetwork -framework CoreLocation -framework MapKit -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/ZConsulting/Library/Developer/Xcode/DerivedData/Fontenay-sous-Bois-dhlecgdgtoldsadoctkyueriyius/Build/Products/Debug-iphoneos/Fontenay-sous-Bois.app/Fontenay-sous-Bois

EDIT:

I did import the libz.1.1.3.dylib framework: enter image description here

The only libz that i got in the Linked frameworks is the libz.1.1.3.dylib enter image description here

Luca
  • 20,399
  • 18
  • 49
  • 70

2 Answers2

6

You did specify the library libz.dylib in the Linked frameworks and Libraries item rather than the direct reference to libz.1.1.3 - in general you should use the most generic version of a library for compilation rather than a more specific one

Secondly, make sure that the libz.dylib is present under the iOS SDK - if it's missing, then it may be a mis-installed SDK (reinstall should fix that).

i.e.

find /Developer/Platforms -name libz.dylib

should result in a non-empty output for a libz.dylib under iPhoneOS5.0.sdk

Also see the answer to iPhone - Linker Error in Xcode 4.2 Preview, which is a similar issue to this.

Community
  • 1
  • 1
Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • I have imported the libz.1.1.3.dylib library, please take a look on my edit, this is working with i compile with the simulator, but since i try to build an archive, i got that. – Luca Mar 21 '12 at 11:49
  • Yes, and the simulator uses a different location to the device. You're better off importing the generic `libz.dylib` rather than the specific `libz.1.1.3`. Try the `find /Developer/Platforms -name libz.1.1.3.dylib` and check that it is found in both `iPhoneOS5.0.sdk` *and* `iPhoneSimulator5.0.sdk`. If it's not found, then I suggest replacing it with just `libz.dylib`. You should have a compelling reason for using the `1.1.3` version of libz to make reference to that specific version (in general these libraries are upwards compatible) – Anya Shenanigans Mar 21 '12 at 11:59
  • The only libz framework i got in the list is the `libz.1.1.3.dylib`, please have a look o my Update. – Luca Mar 21 '12 at 13:03
  • It looks like you have an invalid SDK install in that case - From my 5.0 SDK I see a bunch of `libz.*.dylibs` - `libz.1.1.3.dylib`, `libz.1.2.5.dylib`, `libz.1.dylib` `libz.dylib` and they're the only real file is libz.1.2.5.dylib; the rest are references to that file. I would suggest reinstalling Xcode 4.2 after performing a clean uninstall - follow the instructions in the About Xcode readme for uninstallation, and then reinstall it. Alternatively, use a .pkg extraction tool like pacifist and re-extract the iPhoneOS5.0.sdk over the current one. – Anya Shenanigans Mar 21 '12 at 13:57
2

i got the same error with a different library:

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)

to resolve this, under search paths -> user header search paths -> release i put:

"$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include"

keep in mind that I get this bug only when I archive, and my archive is a based off my release scheme..


update: I got the same problem (on a different occasion/project) for the lpods Library (ie cocoapods).. the way i figured out to solve this is by realizing that the build worked fine on my development scheme but not my debug scheme. basically the development scheme had no for build active architectures only whereas debug had yes. I simply changed debug to no in all the targets under cocoapods

abbood
  • 23,101
  • 16
  • 132
  • 246