[CMake] Creating a library

David Doria daviddoria at gmail.com
Wed Feb 18 12:56:00 EST 2009


Ah of course! I am just used to doing

ADD_EXECUTABLE(Test1 Test1.cpp ${Sources})

So I guess I wasn't thinking and assumed it would be the same for
libraries, but now MyLibs is an actual "thing", not a list of files
like ${Sources} is.

Thanks guys.

David



On Wed, Feb 18, 2009 at 12:46 PM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
> 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
>


More information about the CMake mailing list