1

I can not compile a simple c program without specifying '-march=native', I need to run it as: 'gcc -march=native -o hello hello.c'.

I did:

export CFLAGS='-march=native'
export CXXFLAGS='-march=native'

but didn't help.

 user@server:~$ gcc -march=native -Q --help=target
 ...
 -march=corei7-avx
 ...

Output of gcc -v:

user@server:~$ gcc -v
Using built-in specs.
gcc: error: missing argument to ‘-march=’
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5) 

Where and how can I add this option to be default?

4

1 回答 1

2

两种选择:

  1. 艰辛的道路。gcc -dumpspecs > specs 您可以使用命令转储您的规格文件。现在将此文件放入文件/usr/lib/gcc/x86_64-linux-gnu/4.7/ 夹并编辑它以添加选项,如文档中所述。在您的情况下,我建议从删除所有 march=<something>行开始,这可能会有所帮助。但在这一点上,一般情况下是麻烦和创造力。
  2. 简单的方法:将 gcc 二进制文件重命名为 gcc-4.7 并使用 alias gcc='gcc-4.7 -march=native'
于 2015-03-27T14:30:12.350 回答