[CMake] Static lib in project

Matthias Fulz mfulz at olznet.de
Sat Jan 14 23:54:50 EST 2012


Have the following problem:

the lib is linked, but my testprogram can't link against it,
because it's not found:

Built target
aclibconfg                                                                                                                                                                         
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -ltestlib
collect2: ld returned 1 exit status
make[2]: *** [src/test/test] Error 1
make[1]: *** [src/test/CMakeFiles/test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

I've already added the directories to my target, but still not working:

src/test/CMakeLists.txt
add_executable(test main.cpp)

link_directories(
        ${CMAKE_BINARY_DIR}/src/testlib
        )

include_directories(
        ${CMAKE_SOURCE_DIR}/src/testlib
        )

target_link_libraries(test testlib)


The lib is build under src/testlib/testlib.a

Any help would be really nice !

BR,

Matthias

On Sat, 2012-01-14 at 23:42 +0100, Eric Noulard wrote:
> src/CMakeList.txt
> add_subdirectory(static_lib)
> add_subdirectory(executable1)
> add_subdirectory(executable2)
> 
> src/static_lib/CMakeLists.txt
> add_library(InternalUse STATIC lib.cpp lib.hpp)
> 
> src/executable1/CMakeLists.txt
> add_executable(exe1 main.cpp)
> target_link_libraries(exe1 InternalUse)
> install(TARGETS exe1 DESTINATION bin)
> 
> src/executable2/CMakeLists.txt
> add_executable(exe2 main.cpp)
> target_link_libraries(exe2 InternalUse)
> install(TARGETS exe2 DESTINATION bin)
> 
> should work as expected.
> 
> "only inside this project" would mean
> that you shouldn't install this library.
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120115/6844f138/attachment.pgp>


More information about the CMake mailing list