为什么我会收到 cc1plus: error: unrecognized command line option “-arch”?

发布于 2024-10-06 12:50:23 字数 1525 浏览 6 评论 0原文

/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);
}
/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) 

This simple of a file:

#include <stdlib.h>

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

    return (EXIT_SUCCESS);
}

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

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

发布评论

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

评论(5

昵称有卵用 2024-10-13 12:50:23

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

The -arch option is part of the Apple extensions to gcc. You need to use the gcc supplied by Apple's Developer Tools, Xcode.

世界等同你 2024-10-13 12:50:23

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

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

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

The -arch option is only in the Apple-provided version of gcc. Change CFLAGS (which might be set via your environment, your makefile, or your configure options) so it uses -march or -m32 instead. For example:

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

The difference seems to be that you can specify multiple -arch options to generate universal binaries, whereas -march only generates one at a time.

人│生佛魔见 2024-10-13 12:50:23

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

This error exists in many forms, regardless of the machine or build type.
The solution, in general, is to change the PATH and CROSS_COMPILE variables to include the correct cross compiler.

你的往事 2024-10-13 12:50:23

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

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

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

The macports version of GCC doesn't support the -arch flag. As it turns out Apple's GCC is a wrapper around the real gcc that honors a few special flags before calling the real compiler. The -arch flag is one of these flags. It calls the appropriate compiler for each of the archs specified and then uses lipo to mash all of the object files back together into a "fat" object file.

I just spent a little bit of time getting this Apple GCC wrapper working with macports GCC. If you want the details you can find them here:

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

冬天的雪花 2024-10-13 12:50:23

debian bookworm 的 gcc 源代码中也缺少 -arch。相当蹩脚。导致大量编译失败。

-arch is also missing in debian bookworm's gcc sources. Pretty lame. Makes for lots of failing compiles.

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