I'm attempting to make it easier for other projects to link against the shared libraries we distribute with our project. When I try to take advantage of the EXPORT mechanism, CMake complains that I'm not including the static libraries used to build the shared libraries in the export set. This seems unnecessary to me as the other projects only need to link against the shared library and I don't really want to install the static libraries. This seems to be very similar to this bug, but I might just be misunderstanding how this all works. Here is a minimal example:
CMAKE_MINIMUM_REQUIRED(VERSION 3.2.1)
PROJECT(ExportTest)
ADD_LIBRARY(myStaticLib STATIC staticLib.c)
ADD_LIBRARY(mySharedLib SHARED sharedLib.c)
TARGET_LINK_LIBRARIES(mySharedLib myStaticLib)
INSTALL(TARGETS mySharedLib EXPORT myExport DESTINATION lib)
INSTALL(EXPORT myExport DESTINATION include)
Which results in the following error message:
CMake Error: install(EXPORT "myExport" ...) includes target "mySharedLib"
which requires target "myStaticLib" that is not in the export set.
When using target_link_libraries
like you did, library dependencies are transitive by default. Try:
target_link_libraries(mySharedLib PRIVATE myStaticLib)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With