Skip navigation

If you’re running Gentoo, you probably have “-march=native” in your CFLAGS, since that flag gives gcc permission to examine the running processor and decide for itself what CPU features are available.

If you have any interest in distcc or cross-compiling, though, you most definitely do not want to use that flag; gcc will be making assumptions based on the processor your programs are compiling on, not on the processor your programs will be executing on.

There’s a fairly neat solution to this. Run this line on the machine you’re compiling for, and it will emit the gcc arguments that -march=native would translate to:

gcc -march=native -E -v – </dev/null 2>&1 | sed -n ‘s/.* -v – //p’

You can take the output of that command, add any additional flags you like (in my case, -O2 and -ggdb), and add it to your CFLAGS on that system. Should you choose to use distcc in the future, the machines in your compile pool will use the appropriate set of architecture-specific optimizations.

Incidentally, variations on this line have been floating around the gentoo-users mailing list since this summer; this is the cleanest form I’ve seen of it, which I pulled from a comment in Stefan G. Weichinger’s make.conf file.

Advertisements
%d bloggers like this: