Undefined symbols for architecture armv7

2018-12-31 02:23发布

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?

标签: ios armv7
30条回答
旧人旧事旧时光
2楼-- · 2018-12-31 02:32

I have have multiple @interfaces in the .h file and hadn't yet included the all of the corresponding @implementation directives. Make sure that they are all balanced out.

查看更多
怪性笑人.
3楼-- · 2018-12-31 02:34

Common Causes

The common causes for "Undefined symbols for architecture armv7" are:

  1. 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 the Build 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 the Other Linker Flags section of Build Settings.

  2. 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, expand Compile Sources and add the missing .m files. If this is your issue please upvote Cortex's answer below as well.

  3. 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.

查看更多
妖精总统
4楼-- · 2018-12-31 02:35

I give you more suggestions that you can check when other common suggestions are not help.

If you link with other project(libxxx.a) you might sometimes meet strange problem which you can find the symbol with tools like nm but they just can not find the symbols in ld. Then you should check if the two projects are built in the same flags, some of them may affect the binary format.

  1. check c++ compiler.
  2. check c++ dialect setting.
  3. check c++ runtime type support. (-frtti/-fnortti)
  4. check if there is .a with the same name appears elsewhere, could be beyond the wanted file in the link path list. remove them.
查看更多
谁念西风独自凉
5楼-- · 2018-12-31 02:36

I had a similar issue and saw errors related to "std::"

I changed Build Settings -> Apple LVM 5.0 - Language C++ -> C++ Standard Library

from libc++ (LLVM C++ Standard Library with C++11 support) to libstdc++ (GNU C++ Standard Library)

查看更多
孤独寂梦人
6楼-- · 2018-12-31 02:38

Under Target -> Build Settings -> Apple LLVM compiler language: setting 'C++ Language Dialect' and 'C++ Standard Library' to Compiler default helped solve it.

查看更多
泛滥B
7楼-- · 2018-12-31 02:40

I had a similar issue with that. The class name after _OBJC_CLASS_$_ was actually my class. The reason was I didn't tick "Add to Target" when I drag the source code files into navigation list.

My solution was:

  1. delete the class from the navigation list and choose "remove reference only"

  2. drag the source code files again and make sure the tick box for "add to Target" is ticked. The tick box is just under "Copy if needed" and "Create group".

查看更多
登录 后发表回答