Statically linking shared libraries for cross compilation



  • I am having problems with cross compiling Qt for an external embedded board. I managed to fix several missing dependencies by switching to static compilation, but doing this did not include libstdc++.so.6, which is causing problems still.

    Here are things I have tried:

    1. Adding the -static flag while building Qt
    2. Adding the -static-runtime flag while building Qt
    3. Adding CONFIG += static to my .pro file
    4. Adding CONFIG += staticlib to my .pro file
    5. Adding QMAKE_LFLAGS += -static-libstdc++ to my .pro file
    6. Adding LIBS += -L/opt/Xilinx/SDK/2015.4/arm/lin/libc/usr/lib/ -lstdc++ to my .pro file
    7. Adding LIBS += /opt/Xilinx/SDK/2015.4/arm/lin/libc/usr/lib/libstdc++.a to my .pro file

    None of these things have statically linked the library, when I try to use the executable on my target platform it still fails due to the missing .so

    Can someone explain how to static link libstdc++.so.6 in a QtCreator project?


  • Lifetime Qt Champion

    Hi,

    You don't, you have to first compile libstdc++ statically before you can do that.

    From the looks of it, it seems that your target sysroot is missing libraries. You should take the time to look into that.



  • @SGaist In the location where I have libstdc++.so.6 on my build computer I also have libstdc++.a, is that not the static version? Since I already seem to have that, how do I get Qt to use it instead of the .so.6?


  • Lifetime Qt Champion

    IIRC, if the linker finds both the static and dynamic version in the same folder, it will use the dynamic.

    You can try to pass -Bstatic -lstdc++ or use the full path. You'll have to modify the mkspec you are using to build Qt. You should even consider copying it and give it a new name so you ensure that you can still choose the original when needed.



  • OK, I will try the -Bstatic suggestion.

    Could you elaborate on what you mean by modify the mkspec?

    Additionally, your other suggestion was to use the full path of the static library. The 7th thing I listed in my original post was to add: LIBS += /opt/Xilinx/SDK/2015.4/arm/lin/libc/usr/lib/libstdc++.a to my .pro file, is that not the correct syntax?


  • Lifetime Qt Champion

    Take a looks at the mkspecs folder in Qt's sources.

    It's the set of configuration Qt uses.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.