LIBRARY_PATH环境变量未使用/使用gcc读取

时间:2021-09-11 23:08:13

My LIBRARY_PATH variable is exported, but I still have to pass the -L option to gcc in order to link to my library.

我的LIBRARY_PATH变量已导出,但我仍然必须将-L选项传递给gcc才能链接到我的库。

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.

如果我正确理解GCC文档3.20环境变量影响GCC,应该查看LIBRARY_PATH环境变量,这样我只需要指定-l选项。

When I run

当我跑

gcc -Wall cog.c -L$HOME/lib -lutil

the program is compiled, and I get an a.out as expected.

该程序已编译,我按预期获得a.out。

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).

为了它的价值,我使用Fedora 23 64bit和gcc版本5.3.1 20160406(Red Hat 5.3.1-6)。

1 个解决方案

#1


2  

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

您的发行版可能是启用了multilib的。如果是这种情况,则使用此计算机的体系结构(通常为32位或64位)扩展库的所有路径字符串。所以,如果你指定

$HOME/lib

$ HOME / lib目录

as your search path, multilib might expand it to

作为您的搜索路径,multilib可能会将其扩展为

$HOME/lib/x86_64-linux/4.6

$ HOME / lib目录/ x86_64的Linux的/ 4.6

or

要么

$HOME/lib/x86_32-linux/4.6

$ HOME / lib目录/ x86_32-LINUX / 4.6

You can check if this is the case by invoking gcc once using

您可以通过一次使用调用gcc来检查是否是这种情况

gcc --print-search-dirs

This makes gcc respond with all search paths in use for config and libraries.

这使得gcc响应所有用于配置和库的搜索路径。

#1


2  

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

您的发行版可能是启用了multilib的。如果是这种情况,则使用此计算机的体系结构(通常为32位或64位)扩展库的所有路径字符串。所以,如果你指定

$HOME/lib

$ HOME / lib目录

as your search path, multilib might expand it to

作为您的搜索路径,multilib可能会将其扩展为

$HOME/lib/x86_64-linux/4.6

$ HOME / lib目录/ x86_64的Linux的/ 4.6

or

要么

$HOME/lib/x86_32-linux/4.6

$ HOME / lib目录/ x86_32-LINUX / 4.6

You can check if this is the case by invoking gcc once using

您可以通过一次使用调用gcc来检查是否是这种情况

gcc --print-search-dirs

This makes gcc respond with all search paths in use for config and libraries.

这使得gcc响应所有用于配置和库的搜索路径。