[CMake] Link directories order

Renaud Detry renaudjdetry at airpost.net
Thu Nov 1 07:35:26 EDT 2007


Hello,

I'm having trouble with cmake LINK_DIRECTORIES order. I understand
cmake smart-orders link directory flags. However, flags coming from
the shell env LDFLAGS don't seem to be taken into account in this
smart sort. Is this a feature or a bug?

To illustrate the issue, I slightly modified the example code from

   http://www.cmake.org/HTML/cmakeExample.tar.gz

The only change is in

   cmakeExample.tar.gz:CMakeExample/Hello/CMakeLists.txt

which becomes

# Create a library called "Hello" which includes the source file  
"hello.cxx".
# The extension is already found.  Any number of sources could be  
listed here.
add_library (Hello hello.cxx)

INSTALL(TARGETS Hello
         RUNTIME DESTINATION bin
         ARCHIVE DESTINATION lib
         LIBRARY DESTINATION lib)

As one can see in the attached terminal output, the linker for Demo
looks in /tmp/lib before looking in the build dir:

   /usr/bin/c++ -headerpad_max_install_names -fPIC -L/tmp/lib
   "CMakeFiles/helloDemo.dir/demo.o"
   "CMakeFiles/helloDemo.dir/demo_b.o" -o helloDemo
   -L/Volumes/Data/Users/detryr/tmp/CMakeExample/Hello -lHello

As a result, Demo is linked against an obsolete installed version of
Hello, instead of the local fresh one.

Note that /tmp/lib was empty when I ran cmake.

Cheers,
Renaud.



[detryr at MacBook-Pro] $ export LDFLAGS=-L/tmp/lib           [~/tmp/ 
CMakeExample]
[detryr at MacBook-Pro] $ rm /tmp/lib/libHello.a              [~/tmp/ 
CMakeExample]
rm: /tmp/lib/libHello.a: No such file or directory
[detryr at MacBook-Pro] $ cmake -DCMAKE_INSTALL_PREFIX=/tmp   [~/tmp/ 
CMakeExample]
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/Data/Users/detryr/tmp/ 
CMakeExample
[detryr at MacBook-Pro] $ make VERBOSE=1                      [~/tmp/ 
CMakeExample]
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -H/Volumes/Data/ 
Users/detryr/tmp/CMakeExample -B/Volumes/Data/Users/detryr/tmp/ 
CMakeExample --check-build-system CMakeFiles/Makefile.cmake 0
Clearing dependencies in "Hello/CMakeFiles/Hello.dir/depend.make".
Clearing dependencies in "Hello/CMakeFiles/Hello.dir/depend.internal".
Clearing dependencies in "Demo/CMakeFiles/helloDemo.dir/depend.make".
Clearing dependencies in "Demo/CMakeFiles/helloDemo.dir/ 
depend.internal".
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_start /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles 3
make -f CMakeFiles/Makefile2 all
make -f Hello/CMakeFiles/Hello.dir/build.make Hello/CMakeFiles/ 
Hello.dir/depend
Scanning dependencies of target Hello
cd /Volumes/Data/Users/detryr/tmp/CMakeExample && /usr/local/ 
cmake-2.4.7-Darwin-universal/bin/cmake -E cmake_depends "Unix  
Makefiles" /Volumes/Data/Users/detryr/tmp/CMakeExample /Volumes/Data/ 
Users/detryr/tmp/CMakeExample/Hello /Volumes/Data/Users/detryr/tmp/ 
CMakeExample /Volumes/Data/Users/detryr/tmp/CMakeExample/Hello / 
Volumes/Data/Users/detryr/tmp/CMakeExample/Hello/CMakeFiles/Hello.dir/ 
DependInfo.cmake
make -f Hello/CMakeFiles/Hello.dir/build.make Hello/CMakeFiles/ 
Hello.dir/build
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_report /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles 1
[ 33%] Building CXX object Hello/CMakeFiles/Hello.dir/hello.o
/usr/bin/c++    -o Hello/CMakeFiles/Hello.dir/hello.o -c /Volumes/ 
Data/Users/detryr/tmp/CMakeExample/Hello/hello.cxx
Linking CXX static library libHello.a
cd /Volumes/Data/Users/detryr/tmp/CMakeExample/Hello && /usr/local/ 
cmake-2.4.7-Darwin-universal/bin/cmake -P CMakeFiles/Hello.dir/ 
cmake_clean_target.cmake
cd /Volumes/Data/Users/detryr/tmp/CMakeExample/Hello && /usr/local/ 
cmake-2.4.7-Darwin-universal/bin/cmake -E cmake_link_script  
CMakeFiles/Hello.dir/link.txt --verbose=1
/usr/bin/ar cr libHello.a  "CMakeFiles/Hello.dir/hello.o"
/usr/bin/ranlib libHello.a
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_report /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles  1
[ 33%] Built target Hello
make -f Demo/CMakeFiles/helloDemo.dir/build.make Demo/CMakeFiles/ 
helloDemo.dir/depend
Scanning dependencies of target helloDemo
cd /Volumes/Data/Users/detryr/tmp/CMakeExample && /usr/local/ 
cmake-2.4.7-Darwin-universal/bin/cmake -E cmake_depends "Unix  
Makefiles" /Volumes/Data/Users/detryr/tmp/CMakeExample /Volumes/Data/ 
Users/detryr/tmp/CMakeExample/Demo /Volumes/Data/Users/detryr/tmp/ 
CMakeExample /Volumes/Data/Users/detryr/tmp/CMakeExample/Demo / 
Volumes/Data/Users/detryr/tmp/CMakeExample/Demo/CMakeFiles/ 
helloDemo.dir/DependInfo.cmake
make -f Demo/CMakeFiles/helloDemo.dir/build.make Demo/CMakeFiles/ 
helloDemo.dir/build
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_report /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles 2
[ 66%] Building CXX object Demo/CMakeFiles/helloDemo.dir/demo.o
/usr/bin/c++   -I/Volumes/Data/Users/detryr/tmp/CMakeExample/Hello   - 
o Demo/CMakeFiles/helloDemo.dir/demo.o -c /Volumes/Data/Users/detryr/ 
tmp/CMakeExample/Demo/demo.cxx
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_report /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles 3
[100%] Building CXX object Demo/CMakeFiles/helloDemo.dir/demo_b.o
/usr/bin/c++   -I/Volumes/Data/Users/detryr/tmp/CMakeExample/Hello   - 
o Demo/CMakeFiles/helloDemo.dir/demo_b.o -c /Volumes/Data/Users/ 
detryr/tmp/CMakeExample/Demo/demo_b.cxx
Linking CXX executable helloDemo
cd /Volumes/Data/Users/detryr/tmp/CMakeExample/Demo && /usr/local/ 
cmake-2.4.7-Darwin-universal/bin/cmake -P CMakeFiles/helloDemo.dir/ 
cmake_clean_target.cmake
cd /Volumes/Data/Users/detryr/tmp/CMakeExample/Demo && /usr/bin/c+ 
+     -headerpad_max_install_names -fPIC -L/tmp/lib "CMakeFiles/ 
helloDemo.dir/demo.o" "CMakeFiles/helloDemo.dir/demo_b.o"   -o  
helloDemo  -L/Volumes/Data/Users/detryr/tmp/CMakeExample/Hello -lHello
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_report /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles  2 3
[100%] Built target helloDemo
/usr/local/cmake-2.4.7-Darwin-universal/bin/cmake -E  
cmake_progress_start /Volumes/Data/Users/detryr/tmp/CMakeExample/ 
CMakeFiles 0
[detryr at MacBook-Pro] $ make install                        [~/tmp/ 
CMakeExample]
[ 33%] Built target Hello
[100%] Built target helloDemo
Install the project...
-- Install configuration: ""
-- Install configuration: ""
-- Installing /tmp/lib/libHello.a
-- Install configuration: ""
[detryr at MacBook-Pro] $                                     [~/tmp/ 
CMakeExample]


More information about the CMake mailing list