繁体   English   中英

为什么我得到cc1plus:错误:无法识别的命令行选项“-arch”?

[英]Why do I get cc1plus: error: unrecognized command line option “-arch”?

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/cppapplication_1
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/main.o.d
g++ -arch i386   -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp
cc1plus: error: unrecognized command line option "-arch"
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 311ms)

simpatico$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin10/4.5.1/lto-wrapper
Target: x86_64-apple-darwin10
Configured with: ../gcc-4.5.1/configure --prefix=/opt/local --build=x86_64-apple-darwin10 --enable-languages=c,c++,objc,obj-c++,fortran,java --libdir=/opt/local/lib/gcc45 --includedir=/opt/local/include/gcc45 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.5 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.5 --with-gxx-include-dir=/opt/local/include/gcc45/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --enable-stage1-checking --disable-multilib --enable-fully-dynamic-string
Thread model: posix
gcc version 4.5.1 (GCC) 

这个简单的文件:

#include <stdlib.h>

int main(int argc, char** argv) {

    return (EXIT_SUCCESS);
}

-arch选项是gcc的Apple扩展的一部分。 您需要使用Apple的开发人员工具Xcode提供的gcc

无论机器或构建类型如何,此错误都以多种形式存在。 通常,解决方案是更改PATH和CROSS_COMPILE变量以包含正确的交叉编译器。

-arch选项仅在Apple提供的gcc版本中。 更改CFLAGS (可能通过您的环境,您的makefile或配置选项设置),因此它使用-march-m32代替。 例如:

configure CFLAGS='-m32 -O2' CC=gcc-4.5

区别似乎是您可以指定多个-arch选项来生成通用二进制文件,而-march只能一次生成一个。

GCC的macports版本不支持-arch标志。 事实证明,Apple的GCC是真正的gcc的包装,它在调用真正的编译器之前会尊重一些特殊的标志。 -arch标志是这些标志之一。 它为指定的每个arch调用适当的编译器,然后使用lipo将所有目标文件重新混合成一个“胖”对象文件。

我花了一点时间让这个Apple GCC包装器与macports GCC一起工作。 如果您需要详细信息,可以在此处找到它们:

http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM