[CMake] Problems with cmake, visualstudio generator and add_library / target_link_libraries
Bill Hoffman
bill.hoffman at kitware.com
Wed Sep 24 08:47:55 EDT 2008
Thomas Veith wrote:
> Hi *,
>
> when using a simple CMakeLists.txt like the following:
>
> cmake_minimum_required(VERSION 2.6)
> PROJECT(socket)
>
> add_definitions( -D_CRT_SECURE_NO_WARNINGS )
>
> add_library(socket STATIC ../../src/base64.cpp ../../src/http.cpp
> ../../src/PoolThread.cpp ../../src/ResourceHandler.cpp
> ../../src/socket.cpp ../../src/sslsocket.cpp )
>
> target_link_libraries(socket ws2_32.lib )
> <<<
CMake does not link anything to static libraries. However, if you later
do something like this:
add_executable(foo foo.cpp)
target_link_libraries(foo socket)
Then foo will link to socket and ws2_32. You should not get undefined
symbols from the creation of a static library. Linking static libraries
to static libraries is not portable (can't even do it on other
platforms). You might want to try some windows pragma magic in your
code if you want to do something like this.
-Bill
More information about the CMake
mailing list