LIBRARY_PATH环境变量未被gcc使用/读取 [英] LIBRARY_PATH environment variable not being used / read with gcc
问题描述
我的LIBRARY_PATH变量已导出,但我仍然必须将-L选项传递给gcc才能链接到我的库。
如果我正确理解GCC文档 3.20环境变量影响GCC 时,应查看LIBRARY_PATH环境变量,以便我只需指定-l选项。
当我运行
gcc -Wall cog.c -L $ HOME / lib -lutil
该程序已编译完成,并且按预期得到了a.out。
如果我运行
gcc -Wall cog.c -lutil
我得到一个未定义的引用错误。
据我所知,我正确地导出了环境变量。
cassiopeia〜> export LIBRARY_PATH = $ HOME / lib
cassiopeia〜> ls $ LIBRARY_PATH
libutil.a
任何线索?
值得一提的是,我使用的是Fedora 23 64位版本和gcc版本5.3.1 20160406(Red Hat 5.3.1-6)。
您的发行版可能已启用multilib。如果是这种情况,所有到库的路径字符串都会随着本机的体系结构(通常是32位或64位)进行扩展。因此,如果您指定
$ HOME / lib
作为搜索路径,multilib可能将其扩展为
$ HOME / lib / x86_64-linux / 4.6
或
<$ HOME / lib / x86_32-linux /4.6
您可以通过使用
调用gcc来检查是否属于这种情况
gcc --print-search-dirs
使得gcc响应所有用于配置和库的搜索路径。
My LIBRARY_PATH variable is exported, but I still have to pass the -L option to gcc in order to link to my library.
If I understand the GCC documentation correctly 3.20 Environment Variables Affecting GCC, the LIBRARY_PATH environment variable should be looked so that I only have to specify the -l option.
When I run
gcc -Wall cog.c -L$HOME/lib -lutil
the program is compiled, and I get an a.out as expected.
If I run
gcc -Wall cog.c -lutil
I get an undefined reference error.
As far as I can tell, I've properly exported the environment variable.
cassiopeia~> export LIBRARY_PATH=$HOME/lib
cassiopeia~> ls $LIBRARY_PATH
libutil.a
Any clues?
For what it's worth, I'm using Fedora 23 64bit and gcc version 5.3.1 20160406 (Red Hat 5.3.1-6).
Your distro probably is multilib-enabled. If this is the case, all path strings to libraries are expanded with the architecture for this machine (typically 32-bit or 64-bit). So, if you specify
$HOME/lib
as your search path, multilib might expand it to
$HOME/lib/x86_64-linux/4.6
or
$HOME/lib/x86_32-linux/4.6
You can check if this is the case by invoking gcc once using
gcc --print-search-dirs
This makes gcc respond with all search paths in use for config and libraries.
这篇关于LIBRARY_PATH环境变量未被gcc使用/读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!