[CMake] LINK_DIRECTORIES before ADD_EXECUTABLE?

John Platt jcplatt at dsl.pipex.com
Tue May 19 18:57:30 EDT 2009


Hi Tyler,

Thanks for your answers. Returning to whether the boost libraries are 
statically or dynamically linked, I probably need to use
SET(Boost_USE_STATIC_LIBS ON).

John.


----- Original Message ----- 
From: "Tyler Roscoe" <tyler at cryptio.net>
To: "John Platt" <jcplatt at dsl.pipex.com>
Cc: <cmake at cmake.org>
Sent: Monday, May 18, 2009 11:36 PM
Subject: Re: [CMake] LINK_DIRECTORIES before ADD_EXECUTABLE?


> On Mon, May 18, 2009 at 11:21:17PM +0100, John Platt wrote:
>> INCLUDE_DIRECTORIES( /usr/local/boost_1_39_0 )
>> ADD_LIBRARY( lib1 STATIC ${lib1_srcs} )
>>
>> ADD_EXECUTABLE( lib1test lib1test.cpp )
>> LINK_DIRECTORIES( /usr/local/lib ) # boost stuff
>> TARGET_LINK_LIBRARIES( lib1test lib1 boost_filesystem-gcc42-mt 
>> boost_system-gcc42-mt )
>
> [...]
>
>> If LINK_DIRECTORIES is moved before ADD_EXECUTABLE -
>>
>> LINK_DIRECTORIES( /home/john/lib1/src ) ## works here
>> ADD_EXECUTABLE( lib2test lib2test.cpp )
>> TARGET_LINK_LIBRARIES( lib2test lib2 lib1 boost_filesystem-gcc42-mt 
>> boost_system-gcc42-mt)
>>
>> lib2test links and executes.
>>
>> 1. Are the boost libraries statically or dynamically linked to lib1test?
>
> I believe that depends on whether your boost libraries are static or
> dynamic libraries. Maybe I don't understand the question?
>
>> 2. Why does moving LINK_DIRECTORIES before ADD_EXECUTABLE appear to fix 
>> things?
>
> From the docs for link_directories:
>
> Specify the paths in which the linker should search for libraries. The
> command will apply only to targets created after it is called.
>
>> 3. The location of the boost libraries has not been specfied but lib2test 
>> still links?
>
> /usr/local/lib may be one of the default paths CMake uses when search
> for libraries, or you may have /usr/local/lib in LD_LIBRARY_PATH or a
> similar environment variable.
>
> tyler
> 




More information about the CMake mailing list