GCC如何在默认链接器搜索路径之前添加默认值? LIBRARY_PATH不起作用 [英] GCC how to add before the default linker search path by default? LIBRARY_PATH not working

查看:644
本文介绍了GCC如何在默认链接器搜索路径之前添加默认值? LIBRARY_PATH不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一些旧的boost库文件。我试图找出如何设置一些环境变量来让g ++链接到正确版本的库文件。在/ usr / lib64中(链接这些将失败)以及/ v / users / regel / lib中的新库。所以链接器应该链接到新的库。



命令:

  $ g ++ test.cpp -lboost_system -L / v / users / regel / lib 

连结程式正确。但是,我希望将其设置为链接器的第一个搜索目录,以便每次链接时都不必指定'-L'。



以下环境变量似乎并没有这样做:

  $ LIBRARY_PATH = / v / users / regel / lib g ++ test.cpp -lboost_system 
/tmp/regel/cc4SmBtI.o:在函数`main'中:
test.cpp :( .text + 0x5):对`boost :: system :: system_category()'的未定义引用
collect2:错误:ld返回1退出状态

  $ LD_LIBRARY_PATH = / v / users / regel / lib:$ LD_LIBRARY_PATH g ++ test.cpp -lboost_system 
/tmp/regel/ccUreBZy.o:在函数`main'中:
test.cpp :( .text + 0x5):未定义对`boost :: system :: system_category()'的引用
collect2:error:ld返回1退出状态

尽管阅读了大量相似主题的文章和文章,但我还没有找到解决方案。

解决方案

由于GCC手册表示 LIBRARY_PATH 是将目录添加到库搜索路径的正确环境变量。



如果将 -v 添加到 g ++ 命令中,您应该看到 LIBRARY_PATH ,你应该看到它包含你指定的目录,并将它添加到 collect2 命令中 -L ,但是您会看到它在标准目录(如 -L / usr / lib )后面添加 code>等等。



我不知道如何使 LIBRARY_PATH 中的目录先行,我想你必须使用 -L


I'm trying to figure out how to set some environment variable which would make g++ to link to correct versions of the libraries.

I have some old boost libraries in /usr/lib64 (linking against these will fail) and new libraries in /v/users/regel/lib. So the linker should link against the new libraries.

Command:

$ g++ test.cpp -lboost_system -L/v/users/regel/lib

links the program correctly. However, I wish to set this as the number 1 search directory for the linker so that I don't have to specify '-L' every time I link.

The following environment variables do not seem to do the trick:

$ LIBRARY_PATH=/v/users/regel/lib g++ test.cpp -lboost_system
/tmp/regel/cc4SmBtI.o: In function `main':
test.cpp:(.text+0x5): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status

and

$ LD_LIBRARY_PATH=/v/users/regel/lib:$LD_LIBRARY_PATH g++ test.cpp -lboost_system
/tmp/regel/ccUreBZy.o: In function `main':
test.cpp:(.text+0x5): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status

Despite reading numerous articles and posts on similar subjects, I have not found a solution yet.

解决方案

As the GCC manual says, LIBRARY_PATH is the correct environment variable to add directories to the library search path.

If you add -v to the g++ command you should see the LIBRARY_PATH that it uses, and you should see it includes the directory you have specified, and that it gets added to the collect2 command as -L, but you will see it gets added after the standard directories such as -L/usr/lib etc.

I don't know any way to make the directories in LIBRARY_PATH come first, I think you have to use -L for that.

这篇关于GCC如何在默认链接器搜索路径之前添加默认值? LIBRARY_PATH不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆