Undefined symbols for architecture armv7
This problem has been driving me crazy, and I can't work out how to fix it...
Undefined symbols for architecture armv7:
"_deflateEnd", referenced from:
-[ASIDataCompressor closeStream] in ASIDataCompressor.o
"_OBJC_CLASS_$_ASIDataDecompressor", referenced from:
objc-class-ref in ASIHTTPRequest.o
"_deflate", referenced from:
-[ASIDataCompressor compressBytes:length:error:shouldFinish:] in ASIDataCompressor.o
"_deflateInit2_", referenced from:
-[ASIDataCompressor setupStream] in ASIDataCompressor.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
I think it has to do with:
ld: symbol(s) not found for architecture armv7
But I have added: libz.1.2.3.dylib
and it's not helping, anyone got any ideas?
Solution 1:
Common Causes
The common causes for "Undefined symbols for architecture armv7" are:
-
You import a header and do not link against the correct library. This is common, especially for headers for libraries like QuartzCore since it is not included in projects by default. To resolve:
Add the correct libraries in the
Link Binary With Libraries
section of theBuild Phases
.If you want to add a library outside of the default search path you can include the path in the
Library Search Paths
value in the Build Settings and add-l{library_name_without_lib_and_suffix}
(eg. for libz.a use-lz
) to theOther Linker Flags
section ofBuild Settings
.
-
You copy files into your project but forgot to check the target to add the files to. To resolve:
- Open the
Build Phases
for the correct target, expandCompile Sources
and add the missing.m
files. If this is your issue please upvote Cortex's answer below as well.
- Open the
-
You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:
If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).
Optionally, you could create a fat static library that contains both architectures.
Original Answer:
You have not linked against the correct libz file. If you right click the file and reveal in finder its path should be somewhere in an iOS sdk folder. Here is mine for example
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib
I recommend removing the reference and then re-adding it back in the Link Binary With Libraries section Build Phases of your target.
Solution 2:
I had a similar issue last night and the problem, was related to the fact that I had dragged a class from the Finder to my project in Xcode.
The solution was to go the the Build Phases tab and then the Compile Sources and make sure you drag the class to the list.
Solution 3:
I had a similar issue and I had to check "Build Active Architecture Only" on each of the Project configurations (Debug, Release and Deployment) and in the Build Settings of the Target.
Solution 4:
Another possible cause of "undefined symbol" linker errors is attempting to call a C function from a .mm file. In this case you'll need to use extern "C" {...} when you import the header files.
Linker error calling C-Function from Objective-C++