C++ 未找到 -lboost_system 的库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6721559/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:34:53  来源:igfitidea点击:

library not found for -lboost_system

c++boostmakefileboost-asio

提问by jim

I installed boost using macports. The files appear to be in /opt/local/include/boost/

我使用 macports 安装了 boost。这些文件似乎在 /opt/local/include/boost/

My makefile is no longer working and I get the following error

我的 makefile 不再工作,并且出现以下错误

Undefined symbols:
"boost::system::generic_category()", referenced from:
  __static_initialization_and_destruction_0(int, int)in client.o
  __static_initialization_and_destruction_0(int, int)in client.o
"boost::system::system_category()", referenced from:
  boost::asio::error::get_system_category()    in client.o
  boost::system::error_code::error_code()in client.o
  __static_initialization_and_destruction_0(int, int)in client.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [client] Error 1

at school the solution was to use -lboost_system as an argument to g++, but now that I've taken the project home to my mac, this does not work. I think this is mostly due to the fact that at school the boost files were at usr/local/lib (or somewhere similar).

在学校,解决方案是使用 -lboost_system 作为 g++ 的参数,但现在我已将该项目带回家我的 mac,这不起作用。我认为这主要是因为在学校时 boost 文件位于 usr/local/lib (或类似的地方)。

When I add the -lboost_system argument i get the following message

当我添加 -lboost_system 参数时,我收到以下消息

g++ -I/opt/local/include -lboost_system -o client client.o Packet.o
ld: library not found for -lboost_system
collect2: ld returned 1 exit status
make: *** [client] Error 1

I've tried a few variations using -L and -l, but I can't seem to find a combo that works. At school I also do not have to use -L. I've read a few other posts here about similar problems, but they fixed it by adding -l flags which arent working for me.

我已经使用 -L 和 -l 尝试了一些变体,但我似乎找不到有效的组合。在学校我也不必使用-L。我在这里阅读了一些关于类似问题的其他帖子,但他们通过添加对我不起作用的 -l 标志来修复它。

Help! thanks!

帮助!谢谢!

回答by mu is too short

You're missing a -L/opt/local/lib. You should be able to set the LDFLAGSin your Makefile:

你缺少一个-L/opt/local/lib. 你应该能够LDFLAGS在你的 Makefile 中设置:

LDFLAGS=-L/opt/local/lib

This assumes that the Boost libraries are in /opt/local/libof course.

这假设 Boost 库在/opt/local/lib当然。

If you're not using the usual CXXFLAGSand LDFLAGSvariables in your Makefile, then add the -L/opt/local/libdirectly in your final rule:

如果你没有在你的 Makefile 中使用普通CXXFLAGSLDFLAGS变量,那么-L/opt/local/lib直接在你的最终规则中添加:

client: client.o Packet.o
    g++ -L/opt/local/lib -o client client.o Packet.o -lboost_system

The -Ionly tells the compiler where header files are, the linker needs libraries and you use -Lfor that.

-I只告诉编译器在哪里头文件,链接器需要磁带库,并且使用-L了点。

回答by serup

You could try to look for it in your system like this :

您可以尝试在您的系统中查找它,如下所示:

/sbin/ldconfig -p | grep boost_system | cut -d\> -f2

if the library is installed, then it should show something like this:

如果安装了库,那么它应该显示如下内容:

/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0

or it will show just a blank line

否则它只会显示一个空行

In your case it seems that boost is installed in another place, hence the need for additional linker information, hence the need for the -L switch, if however you have it in /usr/lib, as I have then no need for additional info in makefile

在你的情况下,boost 似乎安装在另一个地方,因此需要额外的链接器信息,因此需要 -L 开关,如果你在 /usr/lib 中有它,那么我不需要额外的信息在生成文件中