I'm using CMake in a project, and I'm trying to statically link some libraries.I've set:
set(BUILD_SHARED_LIBS OFF)set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")set_target_properties(icarus PROPERTIES LINK_SEARCH_END_STATIC 1)
And I've made sure when looking for the actual libraries that I have the *.a version of them.
Currently the project imports:
libPocoNet.a libPocoUtil.a libPocoXML.a libPocoFoundation.a libmysqlclient.a libmysqlpp.a libcrypto++.a CUDA
All libraries are found, and when doing a dynamic/shared linkage, they work fine.I have also tried to set compilation flags:
set(GCC_CXX_FLAGS ${GCC_CXX_FLAGS} "-static-libgcc -static-libstdc++ -static")
But to no avail.While I get no issues while compiling, linkage is throwing alot of undefined reference errors for calls found in the above libraries, i.e:
undefined reference to `mysql_thread_init'undefined reference to `mysql_real_query'undefined reference to `pthread_mutex_unlock'undefined reference to `Poco::ErrorHandler::handle()'
Not in that particular order, and numerous errors for each library.
Looking at the last line of GCC I see:
/usr/bin/c++ -g -g -static-libgcc -static-libstdc++ -static [list of *.cpp files]-o icarus -rdynamic /usr/local/lib/libPocoFoundation.a /usr/local/lib/libPocoNet.a/usr/local/lib/libPocoUtil.a /usr/local/lib/libPocoXML.a -Wl,-Bstatic -lmysqlclient -lmysqlpp -lcrypto++
Which makes me wonder:
- Why are Poco libraries linked as -rdynamic, and there is no -Wl -Bstatic flag? As if they are skipped/excluded from static linkage.
- mysqlclient, mysqlpp and crypto++ seem to be set for static linkage, yet I still get errors
So, could someone please explain to me:
- How do I setup for partial static linkage using CMake
- Is CMAKE_EXE_LINKER_FLAGS the only one I need to set?
- Should I be forcing static linking for mentioned libraries but not for entire project?
Please excuse me if those are too many or too localized questions, I haven't tried this before, and I can't seem to find much info on the net.