[CMake] Simple (?) lib linking question

William A. Hoffman billlist at nycap.rr.com
Mon Aug 7 09:19:41 EDT 2006


At 03:13 AM 8/7/2006, Anders Sundman wrote:
>> At 04:08 AM 8/4/2006, Anders Sundman wrote:
>>>Shouldn't the line:
>>>-> C:\MinGW\bin\g++.exe    -shared -o liba.dll
>>> -Wl,--out-implib,liba.dll.a "CMakeFiles/a.dir/a.obj" -lb
>>>
>>>also contain a -L switch since I have the line
>>> "LINK_DIRECTORIES(${TEST_SOURCE_DIR}/b)" in the cmake file for the
>>> "a"-lib?
>>>
>>>// Anders Sundman
>>
>> It is an ordering problem, you have this:
>>
>> ADD_LIBRARY(liba SHARED liba.cpp)
>> INCLUDE_DIRECTORIES(${TEST_SOURCE_DIR}/libb)
>> LINK_DIRECTORIES(${TEST_SOURCE_DIR}/libb)
>> TARGET_LINK_LIBRARIES(liba libb)
>>
>> The LINK_DIRECTORIES command has to come before the ADD_LIBRARY command.
>>
>> -Bill
>>
>
>Thank you so much! That was it; now I get the -L option I expected.
>
>The example still doesn't compile though :) There seems to be one more
>problem with it, possibly related.
>
>It goes like this: app uses lib a that uses lib b. I have lib b, can
>compile lib a, but when it's time to compile the app, the following build
>command is generated by cmake:
>
>C:\MinGW\bin\g++.exe "CMakeFiles/app.dir/app.obj" -o ../app.exe
>-Lc:\dev\lab\cmtest2\build\a -Lc:\dev\lab\cmtest2\build -la -lb
>
>But the "-lb" option shouldn't be there. The app doesn't want to know
>about the b lib. If I manually remove it and compile "by hand" then it
>works fine.
>
>The cmakelists file for the app never mentions the b lib, so why does
>cmake put the -lb option there?
>
>This is the entire cmakelists file for the app directory:
>
>INCLUDE_DIRECTORIES(${TEST_SOURCE_DIR}/a)
>LINK_DIRECTORIES(${TEST_BINARY_DIR}/a)
>ADD_EXECUTABLE(app app.cpp)
>TARGET_LINK_LIBRARIES(app a)

This is a feature of cmake, it will chain libraries.  There is no
way to turn it off.  Why would this be a problem? 

-Bill



More information about the CMake mailing list