C++ Ubuntu Linux 库路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1895100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ubuntu Linux Library Path
提问by
How do I determine the Ubuntu Linux Library Path? That is, how does the linker know where to got to grab the object files when linking my program?
如何确定 Ubuntu Linux 库路径?也就是说,链接器在链接我的程序时如何知道从哪里获取目标文件?
回答by Dirk Eddelbuettel
Look at /etc/ld.so.conf
and the files in the /etc/ld.so.conf.d/
directory -- that's where it is set.
查看/etc/ld.so.conf
目录中的/etc/ld.so.conf.d/
文件 - 这就是它的设置位置。
回答by Drew Dormann
The file paths can be set explicitly when linking using the -L
parameter, as well as the environment variable LD_LIBRARY_PATH
.
文件路径可以在使用-L
参数和环境变量进行链接时显式设置LD_LIBRARY_PATH
。
There are also some paths hard-coded into the linker, using the -L
param. You can see these with the command:
还有一些路径使用-L
参数硬编码到链接器中。您可以使用以下命令查看这些内容:
gcc -Xlinker -v
回答by viraptor
If it's not a standard path (/lib
, /usr/lib
), you can specify the location with the compiler flag. For g++
, it's -L/some/path/lib
. If you use autotools, you can just configure with LDFLAGS=-L/some/path/lib
if you need a specific path. If configure has been properly designed for the project, it should have a --with-some-library=PATH
option, where you can also specify a path for that library only.
如果它不是标准路径 ( /lib
, /usr/lib
),则可以使用编译器标志指定位置。对于g++
,它是-L/some/path/lib
。如果您使用 autotools,则可以在LDFLAGS=-L/some/path/lib
需要特定路径时进行配置。如果 configure 已为项目正确设计,则它应该有一个--with-some-library=PATH
选项,您还可以在其中指定仅为该库的路径。
回答by Michael Aaron Safyan
When linking, you need to specify the -L flag to indicate where the library is located. At runtime, the dynamic linker uses the paths given in "/etc/ld.so.conf", "/etc/ld.so.conf.d/*" and the value of LD_LIBRARY_PATH.
链接时,需要指定-L 标志来指示库所在的位置。在运行时,动态链接器使用“/etc/ld.so.conf”、“/etc/ld.so.conf.d/*”和LD_LIBRARY_PATH 中给出的路径。
回答by PanCrit
"sudo ldconfig" updates the system's cache if you've just installed something new.
如果您刚刚安装了新的东西,“sudo ldconfig”会更新系统的缓存。