[CMake] Project being (unnecessarily) relinked

Jesper Eskilson jesper at eskilson.se
Wed Sep 12 08:36:51 EDT 2007


Bill Hoffman wrote:
> Jesper Eskilson wrote
>>
>> Well, that turned out to be a little hasty conclusion.
>>
>> In case of linking with a DLL, having paths to both the dll and import
>> lib in LINK_DIRECTORIES avoids relinking. So far, so good.
>>
>> However, I still get relinks due to a dependency on a static library.
>> In this case, I'm unable to add the path using LINK_DIRECTORIES since
>> the path is different depending on the configuration. I'm currently
>> adding the path using the LINK_FLAGS_{DEBUG, ...} target property
>> (which probably is the cause of the relinking).
>>
> Something is really strange here.  I don't understand how this could
> happen.   It would be really good at this
> point if you could create a small example project that shows this
> problem and post it so I can take a look.


> Really you should be using full paths to libraries and not
> LINK_DIRECTORIES anyway.

Why not? Is that a general advice about LINK_DIRECTORIES?

> Something like this:
> target_link_libraries(foo optimized /full/path/to/relbuild/bar.lib debug
> /full/path/to/debugbuild/bar.lib)
> 
> The odd part is that if you do not use full paths then it should never
> relink because of a library
> changing.   Something else is different in your cmakelist file.  Again,
> please create a complete
> example that shows the problem.

I've fixed the problem now. The main culprit was that the path to the
library I was linking against was only passed to link.exe through a
-LIBPATH command line option, i.e. using set_target_property(..
LINK_FLAGS ..). My guess is that this made Visual Studio fail to realize
that the library was up-to-date (or even existed).

I will consider using full paths to TARGET_LINK_LIBRARIES() instead of
LINK_DIRECTORIES().

Anyway, thanks for the help.

--
/Jesper

-- 
/Jesper


More information about the CMake mailing list