error when import zlib in iOS: symbol(s) not found collect2: ld
Question
I have included <zlib.h>
in my iphone application and the source code I was mocking up the sample code of Molecules provided by Brad Larson, however, when I build the project, it returns the error as below. Can anyone point out for me whether this is a library linking problem or am I missing something else?
"_deflate", referenced from: -[NSData(Gzip) gzipDeflate] in NSData+Gzip.o "_inflateEnd",
referenced from: -[NSData(Gzip) initWithGzippedData:] in NSData+Gzip.o "inflateInit2",
referenced from: -[NSData(Gzip) initWithGzippedData:] in NSData+Gzip.o "_inflate",
referenced from: -[NSData(Gzip) initWithGzippedData:] in NSData+Gzip.o "_deflateEnd",
referenced from: -[NSData(Gzip) gzipDeflate] in NSData+Gzip.o "deflateInit2", referenced
from: -[NSData(Gzip) gzipDeflate] in NSData+Gzip.o ld: symbol(s) not found collect2: ld
returned 1 exit status
OTHER TIPS
Add libz to your project. To do this, follow these steps in Xcode:
- Open your project, select your project target and then click the blue project info icon on your toolbar (or press ⌘I)
- Click the + button in the lower-left corner of the screen to add a library, scroll down to the bottom of the library list and select libz.dylib; click the Add button.
- Once you've clicked add, you will see that the library name appears in oyur list of Linked Libraries. You will now be able to build your project without linking errors.
You can use this same method to add any library from the list. If the library does not appear on the list, then you know that it is not part of the standard iPhone SDK and you may need to rethink your solution or build the library statically yourself and link your target to that (if even possible).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow