Xcode / GCC 链接问题:文件不是必需的架构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/486885/
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
Xcode / GCC linking issue: file is not of required architecture
提问by Adrian Grigore
I am trying to port a windows project that includes boost 1.37 and wxwidgets to the Mac. It compiles ok, but the linker gives me a "file is not of required architecture for architecture ppc" error for libz.1.dylib and the same message as a warning a few other libraries. I also get a "duplicate dylib" warning for libz.1.dylib.
我正在尝试将包含 boost 1.37 和 wxwidgets 的 Windows 项目移植到 Mac。它编译正常,但链接器给我一个 libz.1.dylib 的“文件不是体系结构 ppc 所需的体系结构”错误,以及与其他一些库的警告相同的消息。我还收到 libz.1.dylib 的“重复 dylib”警告。
The linker output looks like this:
链接器输出如下所示:
Building target “Gemsweeper Mac” of project “Gemsweeper Mac” with configuration “Debug”
使用配置“Debug”构建项目“Gemsweeper Mac”的目标“Gemsweeper Mac”
Checking Dependencies
检查依赖项
Ld "/Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Debug/Gemsweeper Mac.app/Contents/MacOS/Gemsweeper Mac" normal i386
cd "/Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac"
setenv MACOSX_DEPLOYMENT_TARGET 10.4
/Developer/usr/bin/g++-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk "-L/Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Debug" -L/Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib -L/opt/local/lib "-F/Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Debug" -F/Users/adriangrigore/Library/Frameworks -F/Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks -filelist "/Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/Gemsweeper Mac.LinkFileList" -mmacosx-version-min=10.4 -L/opt/local/lib -L/Users/adriangrigore/wxwidgets-manual/wxMac-2.8.9/lib /opt/local/lib/libboost_system-mt.a /opt/local/lib/libboost_program_options-mt.a /opt/local/lib/libboost_thread-mt.a -arch ppc -arch i386 -framework IOKit -framework Carbon -framework Cocoa -framework System -framework QuickTime -framework OpenGL -framework AGL /Users/adriangrigore/wxwidgets-manual/wxMac-2.8.9/lib/libwx_mac-2.8.a -framework WebKit -lwxexpat-2.8 -lwxtiff-2.8 -lwxjpeg-2.8 -lwxpng-2.8 -lz -lpthread -liconv -framework SDL -framework Cocoa -o "/Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Debug/Gemsweeper Mac.app/Contents/MacOS/Gemsweeper Mac"
ld warning: in /Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/main.o, file is not of required architecture
ld warning: in /Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/variousfunctions-xcode.o, file is not of required architecture
ld warning: in /Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/ParticleLayers.o, file is not of required architecture
ld warning: in /Users/adriangrigore/Documents/Gemsweeper Mac/Gemsweeper MacOS/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/SDLMain.o, file is not of required architecture
ld warning: in /opt/local/lib/libboost_system-mt.a, file is not of required architecture
ld warning: in /opt/local/lib/libboost_program_options-mt.a, file is not of required architecture
ld warning: in /opt/local/lib/libboost_thread-mt.a, file is not of required architecture
ld warning: in /opt/local/lib/libz.dylib, file is not of required architecture
ld warning: in /opt/local/lib/libiconv.dylib, file is not of required architecture
ld: in /opt/local/lib/libz.1.dylib, file is not of required architecture for architecture ppc
collect2: ld returned 1 exit status
ld warning: duplicate dylib /opt/local/lib/libz.1.dylib
ld warning: duplicate dylib /opt/local/lib/libiconv.2.dylib
I'm quite new to the Mac plattform, so any help would be greatly appreciated!
我对 Mac 平台很陌生,所以任何帮助将不胜感激!
Thanks,
谢谢,
Adrian
阿德里安
采纳答案by Keltia
From the messages you've got, most of Gemsweeper Mac and libboost have been compiled with only ppc as architecture. You should configure Xcode to generate universal binaries and probably recompile libboost through MacPorts. Recent MacPorts have a "universal" target that could help although if you don't plan to run it on ppc, you get just recompile it.
从你得到的消息来看,大多数 Gemsweeper Mac 和 libboost 都是仅使用 ppc 作为架构编译的。您应该配置 Xcode 以生成通用二进制文件,并可能通过 MacPorts 重新编译 libboost。最近的 MacPorts 有一个“通用”目标可以提供帮助,尽管如果您不打算在 ppc 上运行它,您只需重新编译它。
You seem to need to recompile zlib and libiconv as well.
您似乎还需要重新编译 zlib 和 libiconv。
回答by Ray Hidayat
Sounds like you need to redownload or rebuild boost for Mac. And whatever dylib is you need to do that to. In simple terms you really just need to reinstall the libraries.
听起来您需要为 Mac 重新下载或重建 boost。无论 dylib 是什么,你都需要这样做。简单来说,您实际上只需要重新安装库。
With boost you don't need to redownload the whole thing again, the sources themselves are multiplatform, it's just the binaries (the libs and such) which change from platform to platform. Chances are you already have downloaded all the sources, so you'll just need to rebuild the library from the sources. http://www.boost.org/doc/libs/1_37_0/more/getting_started/unix-variants.htmlgives you some information about building boost using bjam. I know on windows they have precompiled binaries but I can't see anything about that on the boost website for Mac.
有了 boost,你不需要再次重新下载整个东西,源本身是多平台的,它只是二进制文件(库等)从平台到平台的变化。您可能已经下载了所有源代码,因此您只需要从源代码重建库。http://www.boost.org/doc/libs/1_37_0/more/getting_started/unix-variants.html为您提供了一些有关使用 bjam 构建 boost 的信息。我知道在 Windows 上他们有预编译的二进制文件,但我在 Mac 的 boost 网站上看不到任何相关内容。
回答by Adrian Grigore
Uninstalling and re-installing zlib and libiconv (plus a dozen other dependent libs) with sudo port xxx install +universal helped. Thanks for your quick reply! :-)
使用 sudo port xxx install +universal 卸载并重新安装 zlib 和 libiconv(以及十几个其他依赖库)有帮助。感谢您的快速回复!:-)
回答by Gabe Rainbow
you need to target the native architecture, not two.. that of 'universal'.
您需要针对本机架构,而不是两个..“通用”架构。
that involves setting xcode to 'Native Architecture of Build Machine', 'Build Active Architecture Only' and 'Valid Architectures' depending on your xcode version. but clean all possible architectural variants.
这涉及将 xcode 设置为“构建机器的本机架构”、“仅构建活动架构”和“有效架构”,具体取决于您的 xcode 版本。但清理所有可能的架构变体。
and thats because boost with the default ./b2 install
will only get the native architecture.
那是因为使用默认值提升./b2 install
只会获得本机架构。
try re-installing boost with ./b2 install toolset=intel
尝试重新安装 boost ./b2 install toolset=intel
a possible (and untried) solution is building boost twice.
一个可能的(未经尝试的)解决方案是两次构建提升。
intel ./b2 install --prefix=/usr/local/x64 toolset=intel
英特尔 ./b2 install --prefix=/usr/local/x64 toolset=intel
native ./b2 install --prefix=/usr/local/ppc
本国的 ./b2 install --prefix=/usr/local/ppc