[CMake] Simple (?) lib linking question

Anders Sundman anders.sundman at optonova.se
Fri Aug 4 04:08:03 EDT 2006


William A. Hoffman skrev:
> At 05:20 PM 8/3/2006, Anders Sundman wrote:
>   
>> Hi all!
>>
>> I'm new to cmake and I'm currently trying to get the hang of how it works.
>> Unfortunately, I'm stuck with a simple (?) problem that I can't seem to
>> work out. Any help will be much appreciated.
>>
>> I have created a minimal (OS X) example to demonstrate the problem
>> (attached).
>>
>> In short, the problem is this: I have a 3:rd party lib (libb in my
>> example), that should be used by one of my libs (liba in my example).
>> Finally, my lib should be used by my app. When I try to create my (shared)
>> library, the following error message appears:
>>
>> Scanning dependencies of target liba
>> [ 50%] Building CXX object liba/CMakeFiles/liba.dir/liba.o
>> Linking CXX shared library libliba.dylib
>> /usr/bin/libtool: can't locate file for: -llibb
>> /usr/bin/libtool: file: -llibb is not an object file (not allowed in a
>> library)
>> make[2]: *** [liba/libliba.dylib] Error 1
>> make[1]: *** [liba/CMakeFiles/liba.dir/all] Error 2
>> make: *** [all] Error 2
>>
>> If I build liba as a static library, the following message appears:
>>
>> Scanning dependencies of target liba
>> [ 50%] Building CXX object liba/CMakeFiles/liba.dir/liba.o
>> Linking CXX static library libliba.a
>> [ 50%] Built target liba
>> Scanning dependencies of target appex
>> [100%] Building CXX object app/CMakeFiles/appex.dir/app.o
>> Linking CXX executable appex
>> /usr/bin/ld: can't locate file for: -llibb
>> collect2: ld returned 1 exit status
>> make[2]: *** [app/appex] Error 1
>> make[1]: *** [app/CMakeFiles/appex.dir/all] Error 2
>> make: *** [all] Error 2
>>     
>
> Try make VERBOSE=1
> to see what the link line actually is.
>
> -Bill
>
>
>
>
>   

Thank you all for your input. I modified the example to remove the 
"liblib" ambiguity, but the problem remains.

I have tried to get it to work on a windows machine, but the problem is 
the same. The modified new example has the "b" lib compiled for windows 
(.dll). Unfortunately I can't attach the entire example (due to this 
mailing lists 40KB/message restrictions), but the example without the 
files b/libb.dll and b/libb.dll.a is attached. 

This is the result I get from a VERBOSE compilation:

C:\tmp\cmaketest2\build>mingw32-make VERBOSE=1
"C:\Program Files\CMake 2.4\bin\cmake.exe" -HC:\tmp\cmaketest2 
-BC:\tmp\cmaketest2\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake 2.4\bin\cmake.exe" -E cmake_progress_start 
C:\tmp\cmaketest2\build\CMakeFiles 2
mingw32-make -f CMakeFiles/Makefile2 all
mingw32-make[1]: Entering directory `C:/tmp/cmaketest2/build'
mingw32-make -f a/CMakeFiles/a.dir/build.make a/CMakeFiles/a.dir/depend
mingw32-make[2]: Entering directory `C:/tmp/cmaketest2/build'
mingw32-make[2]: Nothing to be done for `a/CMakeFiles/a.dir/depend'.
mingw32-make[2]: Leaving directory `C:/tmp/cmaketest2/build'
mingw32-make -f a/CMakeFiles/a.dir/build.make a/CMakeFiles/a.dir/build
mingw32-make[2]: Entering directory `C:/tmp/cmaketest2/build'
"C:\Program Files\CMake 2.4\bin\cmake.exe" -E cmake_progress_report 
C:\tmp\cmaketest2\build\CMakeFiles 2
[ 50%] Building CXX object a/CMakeFiles/a.dir/a.obj
C:\MinGW\bin\g++.exe   -Da_EXPORTS   -IC:\tmp\cmaketest2\b   -o 
a/CMakeFiles/a.dir/a.obj -c C:\tmp\cmaketest2\a\a.cpp
Linking CXX shared library liba.dll
cd C:\tmp\cmaketest2\build\a && "C:\Program Files\CMake 
2.4\bin\cmake.exe" -P CMakeFiles\a.dir\cmake_clean_target.cmake
cd C:\tmp\cmaketest2\build\a && "C:\Program Files\CMake 
2.4\bin\cmake.exe" -E cmake_link_script CMakeFiles\a.dir\link.txt 
--verbose=1
C:\MinGW\bin\g++.exe    -shared -o liba.dll -Wl,--out-implib,liba.dll.a 
"CMakeFiles/a.dir/a.obj" -lb
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: 
cannot find -lb
collect2: ld returned 1 exit status
mingw32-make[2]: *** [a/liba.dll] Error 1
mingw32-make[2]: Leaving directory `C:/tmp/cmaketest2/build'
mingw32-make[1]: *** [a/CMakeFiles/a.dir/all] Error 2
mingw32-make[1]: Leaving directory `C:/tmp/cmaketest2/build'
mingw32-make: *** [all] Error 2

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



-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmaketest2.zip
Type: application/x-zip-compressed
Size: 1520 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20060804/445fa6a8/cmaketest2.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: anders.sundman.vcf
Type: text/x-vcard
Size: 362 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20060804/445fa6a8/anders.sundman.vcf


More information about the CMake mailing list