So I’m building a shared library, out of two static libraries.
This answer says the way to do it is to insert -Wl,--whole-archive before my static libs, the -Wl,--no-whole-archive after them.
So what I have in cmake at the moment for the shared library is:
add_library(wittyPlus SHARED empty.cpp)
target_link_libraries(wittyPlus
${wtdbosqlite}
${WT_LIBRARIES}
${DB_LIBRARIES}
${Boost_LIBRARIES}
app models
)
So what I need is for it to add the -Wl,--whole-archive before app and models, then -Wl,--no-whole-archive after them (so that the standard library imports don’t get exported by the shared lib).
What’s the easiest way to do this in CMake ?
Addition: So I’d like to use the standard cmake stuff as much as possible, that way I don’t have to do any extra work for windows builds, as CMake kindly removes the compiler definitions that aren’t supported on the platform being built.
OK, it was much easier than I thought.
So according to the cmake docs:
So the fix was just to:
I don’t know if it’ll work on windows or not, I expect it will as cmake is super clever.
Looking at the result with objdump, it does seem to have a lot of boost stuff in the exports, so I might be doing something wrong.
But it does have the stuff I need to link against it so, that’s a step forward.
Any other answers still appreciated. Basically what I’m trying to do is the same as this question:
CMake: how create a single shared library from all static libraries of subprojects?