[CMake] TARGET_LINK_LIBRARIES with full path libraries

Volker Pilipp volker.pilipp at dectris.com
Wed Sep 17 08:50:40 EDT 2014


> Run e.g.
>         echo "int main() {}"|/opt/XXX/bin/g++ -xc++ - -v
>


The output is

Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/opt/XXX
Thread model: posix
gcc version 4.8.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/XXX/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/cc1plus -quiet -v
-D_GNU_SOURCE - -quiet -dumpbase - -mtune=generic -march=x86-64 -auxbase -
-version -o /tmp/ccXHzSkQ.s
GNU C++ (GCC) version 4.8.2 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.8.2, GMP version 4.3.2, MPFR version
2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2
 /opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/x86_64-unknown-linux-gnu
 /opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/backward
 /opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/include
 /usr/local/include
 /opt/XXX/include
 /opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.8.2 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.8.2, GMP version 4.3.2, MPFR version
2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d8088594c0e624acf8c1ee4300a343b6
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccytHs8u.o /tmp/ccXHzSkQ.s
GNU assembler version 2.17.50.0.6-26.el5 (x86_64-redhat-linux) using BFD
version 2.17.50.0.6-26.el5 20061020
COMPILER_PATH=/opt/XXX/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/:/opt/XXX/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/:/opt/XXX/libexec/gcc/x86_64-unknown-linux-gnu/:/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/:/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/:/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/XXX/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/collect2
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o
/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/crtbegin.o
-L/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2
-L/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../.. /tmp/ccytHs8u.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/crtend.o
/usr/lib/../lib64/crtn.o

I suppose it is the line
LIBRARY_PATH=/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/:/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/XXX/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../:/lib/:/usr/lib/

I see that /usr/lib64 (where libcurl.so.3 resides) is before /opt/XXX/lib
(where libcurl.so.4 resides). That's why g++ links against the wrong
library. However, this problem would not occur if I could stop cmake from
replacing /opt/XXX/lib/libcurl.so by -lcurl :-(

Volker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140917/da9f9b4d/attachment-0001.html>


More information about the CMake mailing list