Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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:
- Adding the -static flag while building Qt
- Adding the -static-runtime flag while building Qt
- Adding CONFIG += static to my .pro file
- Adding CONFIG += staticlib to my .pro file
- Adding QMAKE_LFLAGS += -static-libstdc++ to my .pro file
- Adding LIBS += -L/opt/Xilinx/SDK/2015.4/arm/lin/libc/usr/lib/ -lstdc++ to my .pro file
- 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?
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?
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?
Take a looks at the
mkspecsfolder in Qt's sources.
It's the set of configuration Qt uses.