架构armv7的未定义符号

发布于 2024-11-16 15:21:10 字数 845 浏览 4 评论 0原文

这个问题一直让我发疯,我不知道如何解决它...

    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

我认为这与:

ld: symbol(s) not found for architecture armv7

但我添加了:libz.1.2.3.dylib 和这没有帮助,有人有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

静谧幽蓝 2024-11-23 15:21:11

昨晚我遇到了类似的问题,该问题与我将一个类从 Finder 拖到我在 Xcode 中的项目有关。

解决方案是转到“构建阶段”选项卡,然后转到“编译源”,并确保将类拖到列表中。

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.

灵芸 2024-11-23 15:21:11

我遇到了类似的问题,我必须在每个项目配置(调试、发布和部署)以及目标的构建设置中检查“仅构建活动架构”。

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.

最舍不得你 2024-11-23 15:21:11

“未定义符号”链接器错误的另一个可能原因是尝试从 .mm 文件调用 C 函数。在这种情况下,导入头文件时需要使用 extern "C" {...}。

从 Objective-C++ 调用 C-Function 的链接器错误

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++

心作怪 2024-11-23 15:21:11

我也有类似的问题。 _OBJC_CLASS_$_后面的类名实际上是我的类。原因是我将源代码文件拖到导航列表时没有勾选“添加到目标”。

我的解决方案是:

  1. 从导航列表中删除该类并选择“仅删除引用”

  2. 再次拖动源代码文件并制作确保选中“添加到目标”复选框。复选框位于“如果需要,则复制”和“创建组”下方。

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

无声无音无过去 2024-11-23 15:21:11

通常有一个不带版本标识符的别名链接到当前版本,在本例中 libz.dylib 链接到 libz.1.2.5.dylib。使用基本别名而不是版本化别名。

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.

万水千山粽是情ミ 2024-11-23 15:21:11

当我使用 admob 库时,我遇到了同样的问题,我修复了它,将“体系结构”更改为“标准体系结构armv7,armv7s”,而不包括64位。 构建设置

I had the same problem when I use admob library, I fixed it changing "Architectures" to "Standard architectures armv7, armv7s" without including 64-bit. Build Settings

微暖i 2024-11-23 15:21:11

在目标下 ->构建设置->苹果LLVM编译语言:
将“C++ Language Dialect”和“C++ Standard Library”设置为编译器默认值有助于解决此问题。

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

小ぇ时光︴ 2024-11-23 15:21:11

我只将 libz.1.2.5.dylib 添加到我的项目中,它的工作就像一个魅力。

步骤 -

  1. 转到构建阶段。
  2. 将二进制文件与库链接 - 使用“+”按钮选择要添加的框架和库。
  3. 从列表中选择 libz.1.2.5.dylib。
  4. 构建并运行。

I only added the libz.1.2.5.dylib to my project and it worked like a charm.

Steps -

  1. Go to Build Phases.
  2. Link Binary With library - use the '+' button to choose frameworks and libraries to add.
  3. Select libz.1.2.5.dylib from the list.
  4. Build and run.
错々过的事 2024-11-23 15:21:11

我遇到了类似的问题,并看到与“std::”相关的错误,

我更改了“构建设置”-> Apple LVM 5.0 - 语言 C++ -> libc++ 中的C++ 标准库

(支持 C++11 的 LLVM C++ 标准库)
libstdc++(GNU C++ 标准库)

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)

笑饮青盏花 2024-11-23 15:21:11

如果您的 Target > 下有标记 -ObjC构建设置>其他链接器标志并且您遇到此问题,请考虑将其删除。如果您故意添加它,因为您需要从静态库加载一些通常不会加载的 Obj-C 代码,否则,IE,Obj-C 类别,那么您应该使用 -force_load< /code> 而不是 -ObjC

应相对于您的 Xcode 项目目录。 IE,如果您的目录结构如下所示:

iOSProject
  + iOSAPI.framework
      + iOSAPI
  + iOSAPI.xcodeproj

那么您应该为其他链接器标志设置此标志:

-force_load iOSAPI.framework/iOSAPI

如果您想包含多个这样的库,那么您应该包含一个单独的-force_load每个人都有 行。

-force_load iOSAPI.framework/iOSAPI
-force_load another.framework/another

If you have the flag -ObjC under your Target > Build Settings > Other Linker Flags and you're getting this issue, consider removing it. If you intentionally added it because you need to load some Obj-C code from a static library that wouldn't normally be loaded otherwise, IE, an Obj-C category, then you should use -force_load <path> instead of -ObjC.

<path> should be relative to your Xcode project directory. IE, if your directory structure looks like this:

iOSProject
  + iOSAPI.framework
      + iOSAPI
  + iOSAPI.xcodeproj

Then you should have this flag set for Other Linker Flags:

-force_load iOSAPI.framework/iOSAPI

If you want to include multiple libraries like that, then you should include a separate -force_load line for each of them.

-force_load iOSAPI.framework/iOSAPI
-force_load another.framework/another
如若梦似彩虹 2024-11-23 15:21:11

您的目标可能缺少某些课程。当您重命名/删除/添加新的类文件到项目中时,通常会发生这种情况。要修复将新添加的类添加到某些目标。

在项目导航器(右侧边栏)中选择类,打开实用工具边栏(右侧边栏),从实用工具中选择文件检查器(类似文件的图标),在目标成员选项卡下勾选您的目标。这都是为了避免“删除引用”并通过勾选“添加到目标”技巧再次添加。

所以:选择类别 -> 实用程序(文件检查器) -> 目标会员 -> 勾选您想要的目标。

Probably some classes are missing from your target. This usually happens when you rename/remove/add new classes files to your project. To fix add the newly added classes to some targets.

Select the class in the Project Navigator (right sidebar) , open the Utilities sidebar (right sidebar), from the Utilities select the File Inspector (file like icon), under the Target Membership tab tick your targets. This is all to avoid the "Remove reference" and add again with ticking "Add to targets" trick.

So: Select Class -> Utilities (File Inspector) -> Target Membership -> Tick the targets you want.

执手闯天涯 2024-11-23 15:21:11

我的 .h 文件中有多个 @interface,但尚未包含所有相应的 @implementation 指令。确保它们全部平衡。

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.

双马尾 2024-11-23 15:21:11

以下是我遇到此问题的方法:

我通过将另一个项目中的 .h、.m 和 NIB 拖到我的项目导航器上来添加它们。 Xcode 没有将它们正确添加到构建阶段。

检查我的答案,因为我遇到了类似的问题,我可以通过执行一些步骤来解决。

Here's how I got this problem:

I added a .h, .m and NIB from another project by dragging them onto my project navigator. Xcode didn't add them to the Build Phases properly.

Check my answer because I had a similar problem that I was able to solve by doing some steps.

腹黑女流氓 2024-11-23 15:21:11

如果您正在处理 iOS5 升级,我发现为了编译针对目标 4.3 编写的项目,我只需将项目导航器中的 libz.1.2.3.dynlib 重命名为 libz.1.2.5.dynlib 即可编译。

我的 iPhoneOS50SDK/usr/lib 文件夹没有 libz.1.2.3.dynlib - 不知道这是测试版还是自然升级。

if you're dealing with the iOS5 upgrade, I found that for compiling a project written to target 4.3, I could just rename libz.1.2.3.dynlib in the Project Navigator to libz.1.2.5.dynlib and it compiled.

My iPhoneOS50SDK/usr/lib folder has no libz.1.2.3.dynlib--don't know whether it's a beta thing or just natural upgrade.

执着的年纪 2024-11-23 15:21:11

转到您的项目,单击“构建阶段”、“编译源”,然后将 GameCenterManager.m 添加到列表中。

Go to your project, click on Build phases, Compile sources, Add GameCenterManager.m to the list.

淡淡離愁欲言轉身 2024-11-23 15:21:11

这解决了我的问题:我使用的依赖项不支持armv7。所以我除了删除它之外别无选择。无论如何,Armv7 仅用于非常旧的 iPhone(例如 iPhone 4)。

  • 转到“构建设置/全部”
  • 将“有效架构”设置为“arm64 arm64e”

This fixed my problem: The dependency I am using is not supporting armv7. So I had no other option than to remove it. Armv7 is used for only very old iphones anyway (like iphone 4).

  • Go 'Build Settings / All'
  • Set 'Valid Architectures' to 'arm64 arm64e'
同展鸳鸯锦 2024-11-23 15:21:11

我在这里没有找到这个建议,所以这里是:
如果您的项目有多个目标(即一个用于 OSX,一个用于 iOS),那么您必须为每个目标链接相关库。例如,在我的情况下,我需要 AudioToolbox。我有为 OSX 添加一次,为 iOS 添加一次(在frameworks文件夹下,您必须为每个目标拥有每个库的副本..如果您只看到一个..那么这是一个危险信号)

I didn't find this suggestion here so here it goes:
if your project has more than one target (ie one for OSX and one for iOS) then you must link the relevant libraries for each target.. so for example in my case I needed AudioToolbox.. I had to add it once for OSX and once for iOS (under the frameworks folder, you must have a duplicate of each library for each target.. if you see only one.. then that's a red flag)

一张白纸 2024-11-23 15:21:11

我遇到了 PJSIP 库的问题,

在项目中的其他链接器标志中尝试了以下操作并能够解决该错误:
-框架
基础
-框架
UIKit

上面的链接器标志用于 github 上的 Siphone 项目。这些设置将帮助您解决与 C++ 库链接相关的问题。

I was facing an issue with PJSIP libraries,

Tried the following in other linker flags in project and able to resolve the error:
-framework
Foundation
-framework
UIKit

Above linker flags are used in Siphone Project over github. These settings will help you resolve problems related to linking of C++ libraries.

聆听风音 2024-11-23 15:21:11

最后我想通了,我通过向目标添加缺少的框架来解决这个问题 - >构建阶段 - >将二进制文件与库链接

Finally i've figured it out, I solved this issue by adding absent framework to target->Build Phases->Link Binary With Libraries

满地尘埃落定 2024-11-23 15:21:11

我曾经遇到过这个问题。我意识到在移动类时,我用目标文件夹中的 .h 文件覆盖了 .mm 文件。

修复该问题修复了错误。

I once had this problem. I realized that while moving a class, I had overwritten the .mm file with .h file on the destination folder.

Fixing that issue fixed the error.

我是男神闪亮亮 2024-11-23 15:21:11

当尝试编译将“C++ 标准库”的目标构建设置设置为“libc++”的项目时,我收到“未定义的架构 armv7 符号:”错误(这是必要的,因为该项目使用了 C++ 11 中的某些功能),并且该项目包含一个子项目,该子项目的设置设置为“libstdc++”(或当前的编译器默认值)。

将子项目的“C++ 标准库”设置更改为 libc++ 可以修复该问题,但前提是首先将子项目的部署目标设置为 5.0 或更高版本(libc++ 需要 5.0)。

I received the 'Undefined symbols for architecture armv7:' error when trying to compile a project that had the target build setting for 'C++ Standard Library' set to 'libc++' (necessary as the project was using some features from C++ 11), and the project included a sub-project that had the same setting set to 'libstdc++' (or compiler default as it is currently).

Changing the sub-project's 'C++ Standard Library' setting to libc++ fixed it, but only after first setting the deployment target for the sub-project to 5.0 or above (5.0 is necessary for libc++).

迷爱 2024-11-23 15:21:11

我给你提供了更多建议,当其他常见建议没有帮助时,你可以检查一下。

如果你链接到其他项目(libxxx.a),你有时可能会遇到奇怪的问题,你可以使用 nm 等工具找到符号,但他们就是找不到 ld 中的符号。然后您应该检查这两个项目是否使用相同的标志构建,其中一些可能会影响二进制格式。

  1. 检查c++编译器。
  2. 检查 C++ 方言设置。
  3. 检查 C++ 运行时类型支持。 (-frtti/-fnortti)
  4. 检查是否有同名的.a出现在其他地方,可能超出了链接路径列表中所需的文件。删除它们。

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.
泡沫很甜 2024-11-23 15:21:11

当我在iphone5s上运行应用程序时遇到这个问题,通过将arm64添加到Architectures解决了这个问题。

I got this problem when I run app on iphone5s, it was solved by add arm64 to Architectures.

暖心男生 2024-11-23 15:21:11

我也有同样的问题。我尝试了大量答案中的所有内容,但最终我的问题是:
我正在使用 openCV,所以我需要在我的代码中结合 C++ 代码。为此,您应该将使用 Objective-C 和 C++ 的文件更改为 .mm
我没有更改一个文件,并且该文件与 C++ 代码没有任何联系,但我必须更改它。

I had the same problem. I tried every thing from the huge list of answer but in the end my problem was:
I'm working with openCV so I need to combine C++ code in my code. To do this you should change the files which use objective-c and C++ to .mm
I didn't changed one file and this file has no connection to the C++ code but I had to change it.

天赋异禀 2024-11-23 15:21:11

我在安装 shareKit 时遇到了这个问题。它在模拟器中有效,但在设备上无效。我从其他链接器标志中删除了 -all_load ,并且在模拟器和 iPhone 设备中一切正常。

I had this issue, when installing shareKit. It worked in the simulator, but not on the device. I removed -all_load from the Other Linker Flag and everything works fine in both simulator and iphone device.

仲春光 2024-11-23 15:21:11

就我而言,我添加了一个必须使用 Objective C++ 的框架。我找到了这篇文章:

XCode .m vs. .mm

解释了 main.m 如何需要重命名为 main.mm,以便 Objective-C++ 类也可以被编译。

这为我解决了。

In my case, I'd added a framework that must be using Objective C++. I found this post:

XCode .m vs. .mm

that explained how the main.m needed to be renamed to main.mm so that the Objective-C++ classes could be compiled, too.

That fixed it for me.

这样的小城市 2024-11-23 15:21:11

当模块(文件 .m)不在我正在使用的目标中时,我常常遇到这个问题。

I use to face that issue when the module (file .m) is not in the target that I am working with.

做个ˇ局外人 2024-11-23 15:21:11

对我来说,问题是我忘记.m(实现)中为我的常量设置值

file const kFooKey = @"Foo";

For me the problem was that i forget to set value for my constants in the .m (implementation)

file const kFooKey = @"Foo";
你爱我像她 2024-11-23 15:21:11

我还通过拖放添加了文件。我所做的,我删除了所有文件的引用(不包括框架),然后通过将文件添加到项目选项再次正确添加它们,问题就消失了。

I also added files through Dragging and Dropping. What I did, I removed references of all the files (Excluding frameworks) then added them again properly via Add Files To Project option, problem gone.

圈圈圆圆圈圈 2024-11-23 15:21:10

常见原因

“架构armv7 的未定义符号”的常见原因是:

  1. 导入标头但未链接到正确的库。这很常见,特别是对于像 QuartzCore 这样的库的标头,因为默认情况下它不包含在项目中。解决办法:

    • 构建的将二进制文件与库链接部分中添加正确的库阶段

    • 如果您想在默认搜索路径之外添加库,您可以将该路径包含在库搜索路径中构建设置中的值并将
      -l{library_name_without_lib_and_suffix} 添加到 其他构建设置的链接器标志部分。

  2. 将文件复制到项目中,但忘记检查要将文件添加到的目标 。解决办法:

    • 打开正确目标的构建阶段,展开编译源< /em> 并添加缺少的 .m 文件。如果这是您的问题,请同时投票Cortex 在下面的回答


  3. 包括为另一种体系结构(如主机上的模拟器 i386)构建的静态库。解决办法:

    • 如果您的库供应商有多个库文件要包含在项目中,您需要包含一个用于模拟器 (i386) 的库文件和一个用于设备的库文件(例如 armv7)。

      < /里>

    • (可选)您可以创建一个 包含两种架构的胖静态库


原始答案:

您没有链接到正确的 libz 文件。如果右键单击该文件并在查找器中显示它的路径应该位于 iOS sdk 文件夹中的某个位置。这是我的例子

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib

我建议删除引用,然后将其重新添加回目标的“链接二进制文件与库”部分的“构建阶段”。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文