xcode 令人沮丧的 iPhone 构建错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3570629/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:40:15  来源:igfitidea点击:

Frustrating iPhone Build Error

iphonexcodebuildcocos2d-iphone

提问by LandonSchropp

I've been fighting this for a few hours now and I'm getting fed up. My project builds fine with a debug simulator build , release simulator build and a debug device build, but for some reason it won't build with a release device build. I have a static library containing my cocos2d code, and another static library containing a game engine I wrote.

我已经为此奋斗了几个小时,我已经厌倦了。我的项目使用调试模拟器构建、发布模拟器构建和调试设备构建构建得很好,但由于某种原因,它不会使用发布设备构建构建。我有一个包含我的 cocos2d 代码的静态库,以及另一个包含我编写的游戏引擎的静态库。

Because the game engine contains categories, I had to use the all_load linker flag to get it to run. Without this flag, the code builds fine. However, I get an unrecognized selector sent to instance exception when I try to run the game.

因为游戏引擎包含类别,我不得不使用 all_load 链接器标志来让它运行。没有这个标志,代码构建得很好。但是,当我尝试运行游戏时,我收到一个无法识别的选择器发送到实例异常。

Here's the first build error:

这是第一个构建错误:

ld: duplicate symbol _OBJC_CLASS_$_FontLabel in /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o) and /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o)

Ld build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv6/Shapeless normal armv6
cd /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless
setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -L/Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Release-iphoneos -F/Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Release-iphoneos -filelist /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv6/Shapeless.LinkFileList -dead_strip -ObjC -all_load -miphoneos-version-min=4.0 /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libChipmunk.a /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a /Users/helixed/Dropbox/Documents/Development/iPhone/BlackHawk/build/Release-iphoneos/libBlackHawk.a -framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework OpenAL -framework AVFoundation -framework AudioToolbox -lz -framework iAd -o /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv6/Shapeless

ld: duplicate symbol _OBJC_CLASS_$_FontLabel in /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o) and /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 failed with exit code 1

And here's the second:

这是第二个:

Ld build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv7/Shapeless normal armv7
cd /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless
setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -L/Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Release-iphoneos -F/Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Release-iphoneos -filelist /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv7/Shapeless.LinkFileList -dead_strip -ObjC -all_load -miphoneos-version-min=4.0 /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libChipmunk.a /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a /Users/helixed/Dropbox/Documents/Development/iPhone/BlackHawk/build/Release-iphoneos/libBlackHawk.a -framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework OpenAL -framework AVFoundation -framework AudioToolbox -lz -framework iAd -o /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv7/Shapeless

ld: duplicate symbol _OBJC_CLASS_$_FontLabel in /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o) and /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 failed with exit code 1

This is the only think keeping me from releasing, so I really appreciate the help.

这是唯一让我无法发布的想法,所以我非常感谢您的帮助。

Thanks.

谢谢。

回答by user1046037

I faced a similar problem, I had accidentally included (#import) the implementation file instead of the header file

我遇到了类似的问题,我不小心包含了 (#import) 实现文件而不是头文件

When the compiler throws an error that 2 object files contain a duplicate symbol, check for how you have included (#import) the that duplicate symbol's class in the 2 implementation files.

当编译器抛出 2 个目标文件包含重复符号的错误时,请检查您如何在 2 个实现文件中包含 (#import) 该重复符号的类。

回答by Khash Nejad

I had this problem with adding both Facebook sdk and Dropbox sdk. The problem was both of the SDks are using having JSON lib so I removed one of them ans it works now.

我在添加 Facebook sdk 和 Dropbox sdk 时遇到了这个问题。问题是两个 SDks 都使用了 JSON 库,所以我删除了其中一个,现在它可以工作了。

回答by Henry Balanon

Do you have it twice in your project structure? Check the left side of XCode and look through all the folders and make sure you don't have it in there multiple times.

你的项目结构中有两次吗?检查 XCode 的左侧并查看所有文件夹,并确保您没有多次将它放在那里。

回答by hotpaw2

Do you have a different set of device architectures (armv6, armv7, etc.) in your Release build than in your Debug build settings (either project, or target which overrides project settings)?

在您的发布版本中,您是否有一组与调试版本设置(项目或覆盖项目设置的目标)不同的设备架构(armv6、armv7 等)?

回答by LearnCocos2D

I think the solution to your problem lies in the unrecognized selector issue that you tried to solve using the -all_load flag. I use cocos2d-iphone in a static library and didn't need that flag. If you read up what it does, it should tell you that it's unlikely to be related to your problem:

我认为您的问题的解决方案在于您尝试使用 -all_load 标志解决的无法识别的选择器问题。我在静态库中使用 cocos2d-iphone 并且不需要那个标志。如果您阅读它的作用,它应该告诉您它不太可能与您的问题有关:

What does the -all_load linker flag do?

-all_load 链接器标志有什么作用?

It fixes linking to static libraries containing ONLY categories and NO classes. That certainly isn't true for cocos2d-iphone.

它修复了链接到仅包含类别和没有类别的静态库的问题。对于 cocos2d-iphone 来说,这当然不是真的。

I recommend to figure out why you get unrecognized selector warnings without this flag. If necessary ask another question here.

我建议弄清楚为什么你会在没有这个标志的情况下收到无法识别的选择器警告。如有必要,请在此处提出另一个问题。

You should also turn on the "Unrecognized Selector" build warning in the project's Build Settings, so that you get this warning while compiling as opposed to when it crashes while running the game (then it's too late and you wasted a lot of time). It's one of the settings I alwaysturn on in an Xcode project.

您还应该在项目的构建设置中打开“无法识别的选择器”构建警告,以便在编译时收到此警告,而不是在运行游戏时崩溃(然后为时已晚,浪费了很多时间)。这是我在 Xcode 项目中总是打开的设置之一。