[CMake] Creating a library

Christopher Harvey chris at basementcode.com
Wed Feb 18 12:41:20 EST 2009


Off the top of my head I think
TARGET_LINK_LIBRARIES(Test1 ${MyLibs})
should be
TARGET_LINK_LIBRARIES(Test1 MyLibs)
Also, I think you need to specify a static library if you want one. It seems like a static library is what you want in this case.
I wrote this up really quick, and could be wrong about one or he other, or both. 

Chris.


David Doria wrote:
> If I have many executables in the same project (ie same CMakeLists.txt
> file), it seems like I shouldn't have to do this:
>
> set(Sources File1.cpp File1.cpp )
>
> ADD_EXECUTABLE(Test1 Test1.cpp ${Sources})
>
> ADD_EXECUTABLE(Test2 Test2.cpp ${Sources})
>
> because it is compiling File1 and File2 twice when that is unnecessary.
>
> So I tried to do this:
>
> ADD_LIBRARY(MyLibs ${Sources})
>
> ADD_EXECUTABLE(Test1 Test1.cpp)
> TARGET_LINK_LIBRARIES(Test1 ${MyLibs})
>
> ADD_EXECUTABLE(Test2 Test2.cpp)
> TARGET_LINK_LIBRARIES(Test2 ${MyLibs})
>
> But I get a whole bunch of linker errors - "Undefined reference to ..."
>
> Have I done something wrong / how would I do this?
>
> Thanks,
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
>   



More information about the CMake mailing list