简体   繁体   中英

Clang linker does not look into LD_LIBRARY_PATH

I am trying to build and link a C++, cmake-based project with clang (3.0). This project links to several libraries that are installed in a custom directory /my/dir/. This directory is included in the LD_LIBRARY_PATH and LIBRARY_PATH environment variables. Project builds and links fine with g++.

The link command generated and executed by cmake looks like the following:

/usr/bin/clang++ -O3 stuff.cpp.o -o stuff -rdynamic -lmylib

ld then complains with the following message:

/usr/bin/ld: cannot find -lmylib

The link command above runs fine whenever I manually add -L/my/dir/ . Is there a way to link without specifying the -L flag?

The $LD_LIBRARY_PATH environment variable (and its various alternatives on other UNIX-based platforms) is used at runtime , not link time , to find libraries.

Using -L is the correct approach and cannot be avoided.

Note: A better approach under Linux (you don't specify your platform so I'm guessing) is to correctly configure a file in /etc/ld.so.conf.d/ and avoid using $LD_LIBRARY_PATH altogether.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM