Why do I get cc1plus: error: unrecognized command line option "-arch"?
Asked Answered
B

4

15
/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);
}
Backer answered 8/12, 2010 at 19:1 Comment(2)
How did you build gcc - 4.5.1 is not a standard Apple oneCommentative
using macports: sudo port install gcc45Backer
P
17

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

Percolator answered 8/12, 2010 at 19:7 Comment(1)
MrRoy: What does which g++ and g++ --version show? The first should be /usr/bin/g++ and, with current Xcode 4.6.3 on OS X 10.8, the latter should be i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00).Percolator
C
2

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.

Capitulary answered 18/11, 2011 at 15:18 Comment(0)
A
1

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

Akilahakili answered 2/3, 2012 at 16:52 Comment(0)
G
1

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.

Gatling answered 15/5, 2013 at 20:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.