Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show CMake trick for including a static library into another another library #5

Open
daixtrose opened this issue Jun 29, 2024 · 3 comments
Assignees

Comments

@daixtrose
Copy link
Owner

https://cmake.org/cmake/help/v3.24/manual/cmake-generator-expressions.7.html#genex:LINK_LIBRARY

add_library(lib1 STATIC ...)
add_library(lib2 ...)
target_link_libraries(lib2 PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,lib1>")
@daixtrose daixtrose self-assigned this Jun 29, 2024
@daixtrose
Copy link
Owner Author

daixtrose commented Jun 29, 2024

One may also check https://cmake.org/cmake/help/latest/prop_tgt/LINK_LIBRARIES_ONLY_TARGETS.html

In order to link toolchain-provided libraries by name while still enforcing LINK_LIBRARIES_ONLY_TARGETS, use an imported Interface Library with the IMPORTED_LIBNAME target property:

add_library(toolchain::m INTERFACE IMPORTED)
set_property(TARGET toolchain::m PROPERTY IMPORTED_LIBNAME "m")
target_link_libraries(myExe PRIVATE toolchain::m)

@daixtrose
Copy link
Owner Author

very important. https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html#loading-a-whole-static-library

A common need is to prevent the linker from discarding any symbols from a static library. Different linkers use different syntax for achieving this. The following example shows how this may be implemented for some linkers.

@daixtrose
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant