Swift 2 / iOS 9 - libz.dylib not found

余生长醉 提交于 2019-12-17 15:16:34

问题


I'm using some external codes from google in my new Swift 2.0 project that required "libz.dylib" in earlier versions. After updating to the new XCode / the new SDK.

XCode is now unable to import the libz.dylib and throws some errors

Undefined symbols for architecture i386: "_deflate", referenced from: +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o) "_deflateEnd", referenced from: +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o) "deflateInit2", referenced from: +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o) "_inflate", referenced from: +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o) "_inflateEnd", referenced from: +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o) "inflateInit2", referenced from: +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o) ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

When looking through the available packages in the "build phase" settings I can find "libz.tbd" which seems to be the replacement for the libz.dylib. When importing this lib the linker error stays the same but I get this additional warning:

warning: skipping file '/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/libz.tbd' (unexpected file type 'text' in Frameworks & Libraries build phase)

Any idea what to do?


回答1:


I 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 /usr/lib you can add : libz.dylib and more...
  4. Compile and have fun



回答2:


libz.dylib is now found under libz.tbd quote from the Apple developer forums:

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.

Hopefully more documentation will be coming soon.

edit

To clearify it, i will cite Guitz answer with the updated Content

  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.tbd and more...
  4. Compile and have fun



回答3:


Remove all dynamic libraries (dylib) from the linking with binaries phase. It will find these libraries on its own.




回答4:


I have this problem in objective-c project.ios9.1,xcode7.1

1.Go to Target> Build Phases >Link Binary with Librairies > +

2.select libz.tbd and add it

It worked for me




回答5:


libz.dylib is the dynamic lib for Zlib, You can install Zlib from here http://zlib.net/




回答6:


You can add libz.1.dylib from location:/usr/lib/

  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.1.dylib

It worked for me.




回答7:


You can also add the lybz.dylib from "Other Linker Flags" in the Build Settings by adding the argument -lz.

I had to do this because, using the method where you reference the library from /usr/lib, when I deployed my app to our testers the .dylib library could not resolve and caused the app to crash on launch.




回答8:


Meanwhile you can use previous SDK. This is my answer for libsqlite3:

https://stackoverflow.com/a/30981161/627794

Edit: (link content added)

Open terminal, type (change to your desired library, e.g. libz)

locate libsqlite3.dylib

You'll find several files like these:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libsqlite3.dylib
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libsqlite3.dylib

Go to your project's setting -> Build Phases -> Link with Binaries. Add BOTH files by clicking +, then Add Other. Hit Cmd-Shift-G, and copy-paste the file path. Click Open.

If you install sqlite3 using macports, remove /opt/local/lib from Library Search Path in Build Settings.



来源:https://stackoverflow.com/questions/30815806/swift-2-ios-9-libz-dylib-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!