ios 架构 armv7 的未定义符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6429494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined symbols for architecture armv7
提问by Alex Trott
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?
但我补充说:libz.1.2.3.dylib
这没有帮助,有人有任何想法吗?
回答by Joe
Common Causes
常见原因
The common causes for "Undefined symbols for architecture armv7" are:
“架构 armv7 的未定义符号”的常见原因是:
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 belowas well.
- Open the
You include a static library that is built for another architecturelike 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 librarythat contains both architectures.
您导入了一个标头并且没有链接到正确的库。这很常见,特别是对于 QuartzCore 等库的头文件,因为默认情况下它不包含在项目中。解决:
添加正确的资料库中
Link Binary With Libraries
的部分Build Phases
。如果要添加默认的搜索路径的图书馆外,你可以包括在路径
Library Search Paths
中生成设置值,并添加-l{library_name_without_lib_and_suffix}
(如,对于libz.a使用-lz
)的Other Linker Flags
部分Build Settings
。
您将文件复制到项目中,但忘记检查目标以将文件添加到. 解决:
- 打开
Build Phases
正确的目标,展开Compile Sources
并添加丢失的.m
文件。如果这是您的问题,请在下面为Cortex 的回答点赞。
- 打开
您包括一个为其他架构(如 i386)(主机上的模拟器)构建的静态库。解决:
如果你从你的库供应商的多个库文件的项目,包括您需要包括一个用于模拟器(I386)和一个用于设备(ARMv7的举例)。
或者,您可以创建一个包含这两种架构的胖静态库。
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
您没有链接到正确的 libz 文件。如果您右键单击该文件并在 finder 中显示它的路径应该在 iOS sdk 文件夹中的某个位置。这是我的例子
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib
/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.
我建议删除引用,然后将其重新添加回 Link Binary With Libraries 部分 Build Phases 你的目标。
回答by Cortex
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.
昨晚我遇到了类似的问题,这个问题与我将一个类从 Finder 拖到我在 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.
解决方案是转到 Build Phases 选项卡,然后转到 Compile Sources 并确保将类拖到列表中。
回答by Alex Zavatone
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.
我有一个类似的问题,我不得不在每个项目配置(调试、发布和部署)和目标的构建设置中检查“仅构建活动架构”。
回答by user2166865
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.
“未定义的符号”链接错误的另一个可能的原因是试图调用从.mm文件中的C函数。在这种情况下,您需要在导入头文件时使用 extern "C" {...}。
回答by syoleen
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.
我有一个类似的问题。_OBJC_CLASS_$_ 后面的类名实际上是我的类。原因是当我将源代码文件拖到导航列表中时,我没有勾选“添加到目标”。
My solution was:
我的解决方案是:
delete the class from the navigation list and choose "remove reference only"
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".
从导航列表中删除该类并选择“仅删除引用”
再次拖动源代码文件并确保勾选“添加到目标”的复选框。复选框位于“如果需要复制”和“创建组”下方。
回答by zaph
There is usually a alias without the version identifier that is linked to the current version, in this case libz.dylib is linked to libz.1.2.5.dylib. Use the base alias instead of the versioned one.
通常有一个没有版本标识符的别名链接到当前版本,在这种情况下 libz.dylib 链接到 libz.1.2.5.dylib。使用基本别名而不是版本化的别名。
回答by user1368045
Under Target -> Build Settings -> Apple LLVM compiler language: setting 'C++ Language Dialect' and 'C++ Standard Library' to Compiler default helped solve it.
在 Target -> Build Settings -> Apple LLVM compiler language 下:将 'C++ Language Dialect' 和 'C++ Standard Library' 设置为 Compiler default 有助于解决它。
回答by girish_vr
I only added the libz.1.2.5.dylib to my project and it worked like a charm.
我只将 libz.1.2.5.dylib 添加到我的项目中,它就像一个魅力。
Steps-
步骤-
- Go to Build Phases.
- Link Binary With library - use the '+' button to choose frameworks and libraries to add.
- Select libz.1.2.5.dylib from the list.
- Build and run.
- 转到构建阶段。
- Link Binary With library - 使用“+”按钮选择要添加的框架和库。
- 从列表中选择 libz.1.2.5.dylib。
- 构建并运行。
回答by Andrew Soltan
I had a similar issue and saw errors related to "std::"
我不得不涉及到类似的问题和错误锯“的std ::”
I changed Build Settings -> Apple LVM 5.0 - Language C++ -> C++ Standard Library
我更改了 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)
从 libc++(支持 C++11 的 LLVM C++ 标准库)到 libstdc++(GNU C++ 标准库)
回答by pabloverd
I had the same problem when I use admob library, I fixed it changing "Architectures" to "Standard architectures armv7, armv7s" without including 64-bit.
我在使用 admob 库时遇到了同样的问题,我修复了将“架构”更改为“标准架构 armv7、armv7s”而不包括 64 位的问题。