qtgccqbs

How to pass strip flag to linker in release mode in QBS?


I'm using QBS 1.10.1 in Qt Creator 4.5.1 , under MSYS2.

I would like to pass -s to g++ when invoked for the link step, to reduce the size of the release mode binary. How do I do this?

So far I have tried as suggested by the documentation:

   cpp.driverFlags: ["-municode", "-static", "-static-libgcc", "-static-libstdc++"]

    Properties {
        condition: qbs.configuration === "Release"
        cpp.driverFlags: outer.concat("-s")
    }

however it does not actually pass the -s in Release mode, i.e. it's as if the Properties block were not there.

Note: The cpp.driverFlags option actually passes flags to all instances of g++, not just link steps; however I have been unable to find a way to only specify flags for the link step. The g++ is smart enough to ignore those flags if it wasn't a link step. The cpp.linkerFlags field actually transforms the flags to a -Wl,"flag" option which is not the right behaviour for these flags.


Solution

  • There are two problems with your code:

    1. You should not test for the value of qbs.configuration, which is an arbitrary string set by users. Instead, use qbs.buildVariant, where "release" (all lower case!) is a known value.

    2. -s is not a driver flag, but an actual linker flag, i.e. an option that ld understands. Therefore, you should use cpp.linkerFlags. The option will be automatically escaped if the gcc frontend is used for linking.