Search code examples
c++clinuxdebiandpkg

Compilation flags to build runtime on linux machines


What compiler flags are used to build standard c/c++ libraries like glibc and libstdc++? Are they same across the distributions like debian, fedora, archlinux etc?

On debian machines there is dpkg-buildflags but I'm not sure if they are overridden for critical runtime libraries.


Solution

  • The one common factor is -O2, with -O2 -g (enabling gdb debugging symbols) being the most common. -O2 is definitely the expected optimization level maintainers assume packages should be compiled at.

    If you look at debian/rules in Debian source packages (or -debian.tar.* tarballs), you'll usually find HOST_CFLAGS and HOST_CXXFLAGS describing the C and C++ compiler flags used when the source package is built using Debian tools.

    This is documented in for example the man 1 dpkg-buildflags man page: "The default value set by the vendor includes -g and the default optimization level (-O2 usually, or -O0 if the DEB_BUILD_OPTIONS environment variable defines noopt)."

    Outside Debian, Gentoo recommends -O2 -pipe and a -march= for the current architecture. (The -pipe option tells GCC to use pipes instead of temporary files during the build, which is usually faster but uses more RAM, during the build. It has no effect on the compiled binaries.)

    Embedded systems like OpenWRT often use -Os instead, to generate smaller binaries.