I compile a dynamic and static version of my library on Debian 7. My user wants to use the library on RHEL6, so after reading many posts it seemed linking libstdc++ statically should fix the issue.
I am using qmake
, so in the .pro
file I added
unix: QMAKE_CXXFLAGS_RELEASE += -static-libstdc++ -static-libgcc -fvisibility=hidden -w
Then I execute following command:
qmake MyLibrary.pro -spec linux-g++-64 "CONFIG += release"
and the output is
g++ -c -m64 -pipe -O2 -static-libstdc++ -static-libgcc -fvisibility=hidden -w -Wall -W -D_REENTRANT -fPIC -DMYLIBRARY_LIBRARY -DQT_NO_DEBUG -DQT_PLUGIN -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4 -IMyLibrary/Curl/include -I. -o LexAbstraction.o MyLibrary/LexAbstraction.cpp
g++ -c -m64 -pipe -O2 -static-libstdc++ -static-libgcc -fvisibility=hidden -w -Wall -W -D_REENTRANT -fPIC -DMYLIBRARY_LIBRARY -DQT_NO_DEBUG -DQT_PLUGIN -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4 -IMyLibrary/Curl/include -I. -o MyLibrary.o MyLibrary/MyLibrary.cpp
g++ -c -m64 -pipe -O2 -static-libstdc++ -static-libgcc -fvisibility=hidden -w -Wall -W -D_REENTRANT -fPIC -DMYLIBRARY_LIBRARY -DQT_NO_DEBUG -DQT_PLUGIN -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4 -IMyLibrary/Curl/include -I. -o LexBotan.o MyLibrary/LexBotan.cpp
g++ -c -m64 -pipe -O2 -static-libstdc++ -static-libgcc -fvisibility=hidden -w -Wall -W -D_REENTRANT -fPIC -DMYLIBRARY_LIBRARY -DQT_NO_DEBUG -DQT_PLUGIN -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4 -IMyLibrary/Curl/include -I. -o LexCrypter.o MyLibrary/LexCrypter.cpp
g++ -c -m64 -pipe -O2 -static-libstdc++ -static-libgcc -fvisibility=hidden -w -Wall -W -D_REENTRANT -fPIC -DMYLIBRARY_LIBRARY -DQT_NO_DEBUG -DQT_PLUGIN -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4 -IMyLibrary/Curl/include -I. -o LexHelper.o MyLibrary/LexHelper.cpp
rm -f libMyLibrary.so
g++ -m64 -Wl,-O1 -shared -o libMyLibrary.so LexAbstraction.o MyLibrary.o LexBotan.o LexCrypter.o LexHelper.o -L/usr/lib/x86_64-linux-gnu -lpthread
But when I execute
ldd -v libMyLibrary.so | grep GLIBCXX
It gives following output:
libstdc++.so.6 (GLIBCXX_3.4.15) => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.9) => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4) => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
-static-libstdc++
and -static-libgcc
are linkage options, but you are
passing them for compilation (where they are ignored) and not for linkage.
C++ compile options go in QMAKE_CXXFLAGS_{RELEASE|DEBUG}
. Linkage
options go in QMAKE_LFLAGS_{RELEASE|DEBUG}
.
-fvisibility
is a compile option, so it should remain in QMAKE_CXXFLAGS_RELEASE