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?

This should fix your problem:

TARGET_LINK_LIBRARIES(Test2 MyLibs)

-Bill
_______________________________________________
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

Reply via email to