2

I have a shared library libtest.so built on Linux. It links to several shared libraries. Now I have some third party static libraries to link to libtest.so. I am aware this is possible by calling gcc directly:

Can I mix static and shared-object libraries when linking?

My question is how to do the same thing with CMake?

colddie
  • 1,029
  • 1
  • 15
  • 28

1 Answers1

0

I don't see the problem. With your static library, you can do this:

target_link_libraries(my_target_or_executable /home/me/somedir/mymagiclib.a)

Or

target_link_libraries(my_target_or_executable -L/home/me/somedir/)
target_link_libraries(my_target_or_executable mymagiclib.a)

I even linked to shared libraries yesterday this way. Because I had a conflict in gcc's address sanitizer library coming from multiple sources.

Notice however the difference with linking to a library, the normal way. For your libtest.a, you do this:

target_link_libraries(my_target_or_executable -ltest)

Notice that you dropped the lib prefix here. But don't do this when you want to specify the library manually.

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189