<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 17, 2014 at 12:58 PM, Nils Gladitz <span dir="ltr"><<a href="mailto:nilsgladitz@gmail.com" target="_blank">nilsgladitz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 09/17/2014 12:29 PM, Volker Pilipp wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have encountered the following problem with cmake 3.0.1.<br>
Under certain circumstances TARGET_LINK_LIBRARIES replaces<br>
"/path/to/libXXX.so" by "-lXXX". The problem occurred when I used a<br>
non-standard compiler at /opt/XXX/bin/g++ and added the library<br>
/opt/XXX/lib/libXXX.so to TARGET_LINK_LIBRARIES.<br>
In particular CMakeLists.txt reads:<br>
<br>
"SET(CMAKE_CXX_COMPILER /opt/XXX/bin/g++)<br>
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)<br>
PROJECT(XXX)<br>
add_executable(xxx xxx.cpp)<br>
target_link_libraries(xxx /opt/XXX/lib/libXXX.so)"<br>
<br>
When running make VERBOSE=1 produces output like<br>
<br>
/opt/XXX/bin/g++ (...) -lXXX<br>
<br>
which is not the same as<br>
/opt/XXX/bin/g++ (...) /opt/XXX/lib/libXXX.so<br>
</blockquote>
<br></span>
I think CMake reverts to linking by name if either the library is in an implicit linker directory (e.g. a directory the linker searches by default) or if the shared library does not have an SONAME.<br>
<br>
Which library does -lXXX resolve to?<br>
e.g. why aren't the two command lines equivalent for you?<br></blockquote><div> </div><div>-lXXX stands in the actual case for libcurl.so. I have both /usr/lib4/libcurl.so.3 and /opt/XXX/llib/libcurl.so.4 installed and I want my program to be linked against the latter one. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Specifically which library does the linker (ld) pick up;<br>
not the runtime loader (ld.so).</blockquote><div><br></div><div>An ldd on the executable produces</div><div>libcurl.so.3 => /usr/lib64/libcurl.so.3</div><div><br></div><div>Depending on LD_LIBRARY_PATH, (or rpath,...)  I would have expected something like this </div><div>libcurl.so.4 => NOT FOUND</div><div>or</div><div>libcurl.so.4 => /opt/XXX/lib/libcurl.so.4</div><div><br></div><div>Volker</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote></div></div></div>