[CMake] Problems with cmake, visualstudio generator and add_library / target_link_libraries

Thomas Veith veith.th at googlemail.com
Wed Sep 24 09:21:33 EDT 2008


Hi Bill,

Thanks a lot!

I did

add_executable(foo foo.cpp)
add_dependencies(foo socket)

and wasnt aware that I also need

target_link_libraries(foo socket)

Now it works!

Thank you a lot for your help!

Best regards,
Thomas

2008/9/24 Bill Hoffman <bill.hoffman at kitware.com>:
> 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