Balazs Varhegyi
Balazs Varhegyi

Reputation: 1041

How to add '-march=' as default option to gcc?

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?

Upvotes: 1

Views: 3567

Answers (1)

Konstantin Vladimirov
Konstantin Vladimirov

Reputation: 7009

Two options:

  1. Hard way. You may dump your specs file with gcc -dumpspecs > specs command. Now put this file to /usr/lib/gcc/x86_64-linux-gnu/4.7/ folder and edit it to add option as described in documentation. In your case I suggest to start from removing all march=<something> lines, this might trivially help. But general case is troubles and creativity at this point.
  2. Easy way: rename gcc binary to, say gcc-4.7 and make alias with alias gcc='gcc-4.7 -march=native'

Upvotes: 2

Related Questions