[CMake] Relinking static libs

Bill Hoffman bill.hoffman at kitware.com
Wed Apr 9 08:35:17 EDT 2008


Ilya Shvetsov wrote:
> On Wed, 09 Apr 2008 10:55:35 +0300, Jean Lepropre
> <jean.lepropre at star-apic.com> wrote:
> 
>> Hi,
>>
>> I have a somewhat strange problem when linking with static libraries. I
>> have an executable that
>> links to a static library. If I modify only a source (cpp) file of the
>> static lib, the lib is rebuilt and
>> reinstalled but the executable is not relinked to the static lib (so
>> changes are not reflected in the
>> executable...).
>>
> 
> I have the similar problem.
> I use MSVC NMake Generator
> Library comes from external engine.
> 
> 
You must use a FULL path to the library or CMake will not know what 
depend information to add.  If you have:
add_executable(foo foo.c)
link_directories(foobar)
target_link_libraries(foo A B C)

And A, B and C are libraries in the foobar directory that are not built 
by CMake, then there will be no depends on the external libraries as 
CMake does not know where they are.

The correct thing to do would be:

find_library(ALIB A)
find_library(BLIB B)
find_library(CLIB C)
target_link_libraries(foo "${ALIB}" "${BLIB}" "${CLIB}")

Then CMake will have the full path to A,B, and C, and if one of them 
changes foo will be relinked.

-Bill



More information about the CMake mailing list