简体   繁体   English

Clang链接器不会查看LD_LIBRARY_PATH

[英]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). 我正在尝试使用clang(3.0)构建和链接基于C ++,cmake的项目。 This project links to several libraries that are installed in a custom directory /my/dir/. 此项目链接到安装在自定义目录/ my / dir /中的多个库。 This directory is included in the LD_LIBRARY_PATH and LIBRARY_PATH environment variables. 该目录包含在LD_LIBRARY_PATH和LIBRARY_PATH环境变量中。 Project builds and links fine with g++. 项目使用g ++构建和链接。

The link command generated and executed by cmake looks like the following: 由cmake生成并执行的链接命令如下所示:

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

ld then complains with the following message: ld然后抱怨以下消息:

/usr/bin/ld: cannot find -lmylib

The link command above runs fine whenever I manually add -L/my/dir/ . 每当我手动添加-L/my/dir/时,上面的链接命令就可以正常运行。 Is there a way to link without specifying the -L flag? 有没有指定-L标志链接的方法?

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. $LD_LIBRARY_PATH环境变量(及其在其他基于UNIX的平台上的各种替代方案)在运行时使用 ,而不是链接时 ,用于查找库。

Using -L is the correct approach and cannot be avoided. 使用-L是正确的方法,无法避免。

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. 注意:在Linux下更好的方法(你没有指定你的平台,所以我猜)是在/etc/ld.so.conf.d/正确配置文件,并避免使用$LD_LIBRARY_PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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