Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22006

CMake and Static Linking

$
0
0

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:

  1. Why are Poco libraries linked as -rdynamic, and there is no -Wl -Bstatic flag? As if they are skipped/excluded from static linkage.
  2. mysqlclient, mysqlpp and crypto++ seem to be set for static linkage, yet I still get errors

So, could someone please explain to me:

  1. How do I setup for partial static linkage using CMake
  2. Is CMAKE_EXE_LINKER_FLAGS the only one I need to set?
  3. 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.


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>