[CMake] Relinking static libs

Jean Lepropre jean.lepropre at star-apic.com
Thu Apr 10 03:32:20 EDT 2008


Ok, I have similar instructions and it does not work (relink is not done):


1. In top-level CMakeLists.txt:
...
ADD_SUBDIRECTORY(libs/bar)
ADD_SUBDIRECTORY(applications/foo)
...


2. In libs/bar/CMakeLists.txt:
...
ADD_LIBRARY(bar STATIC ...)
...


3. In applications/foo/CMakeLists.txt:
...
LINK_DIRECTORIES(${foo_BINARY_DIR}/../../libs/bar)
ADD_EXECUTABLE(foo ...)
TARGET_LINK_LIBRARIES(foo bar ...)
...


4. In generated applications/foo/CMakeFiles/foo.dir/build.make, there is 
no
dependence on libbard.a.

What's wrong?

Thanks for your help.

Cheers,
Jean.




Bill Hoffman <bill.hoffman at kitware.com> 
09/04/08 18:00

To
Jean Lepropre <jean.lepropre at star-apic.com>
cc
cmake at cmake.org
Subject
Re: [CMake] Relinking static libs






Jean Lepropre wrote:
> Hi Bill,
> 
> Is it the same thing if static lib is built by CMake?
> 
No, if CMake is building the library as part of the project, you link it 
by the target name of the library.

Like this:

add_library(bar STATIC ...)
add_executable(foo ...)
target_link_libraries(foo bar)

CMake will recognize bar as the static library and put in the correct 
depend information.

-Bill




More information about the CMake mailing list