[CMake] How to link libraries correctly?
Brad King
brad.king at kitware.com
Fri Sep 22 08:56:20 EDT 2006
Enrico Scholz wrote:
> Hello,
>
> consider the following CMakeLists.txt
>
> ----
> file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/bar.c "void foo() { }\n")
> file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/foo.c "void bar() { }\n")
>
> add_library(foo SHARED ${CMAKE_CURRENT_BINARY_DIR}/foo.c)
> target_link_libraries(foo -lz -lcups -lcrypt)
>
> add_library(bar SHARED ${CMAKE_CURRENT_BINARY_DIR}/bar.c)
> target_link_libraries(bar foo)
> ----
>
> This:
> * creates a library 'libfoo.so' and a library 'libbar.so'
> * 'libfoo.so' depends on lot of other (dynamic) system-libraries
> * 'libbar.so' depends only on 'libfoo.so'
>
> 'cmake' seems to mislink the example above; after make, 'libbar.so'
> depends on the all the stuff which is brought in by 'libfoo' already:
http://www.cmake.org/Wiki/CMake_FAQ#Why_are_libraries_linked_to_my_shared_library_included_when_something_links_to_it.3F
-Brad
More information about the CMake
mailing list