找不到 -lboost_system 的库

发布于 2024-11-24 09:06:04 字数 1118 浏览 1 评论 0原文

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

我的 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

在学校收到以下错误,解决方案是使用 -lboost_system 作为 g++ 的参数,但现在我已经采取了项目主页到我的Mac,这不起作用。我认为这主要是因为在学校,boost 文件位于 usr/local/lib (或类似的地方)。

当我添加 -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

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

帮助!谢谢!

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

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

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

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

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.

Help! thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋千易 2024-12-01 09:06:04

您缺少 -L/opt/local/lib。您应该能够在 Makefile 中设置 LDFLAGS

LDFLAGS=-L/opt/local/lib

当然,这是假设 Boost 库位于 /opt/local/lib 中。

如果您在 Makefile 中不使用常用的 CXXFLAGSLDFLAGS 变量,则直接添加 -L/opt/local/lib你的最终规则:

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

-I 只告诉编译器头文件在哪里,链接器需要库,你可以使用 -L 来实现。

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

LDFLAGS=-L/opt/local/lib

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

If you're not using the usual CXXFLAGS and LDFLAGS variables in your Makefile, then add the -L/opt/local/lib directly in your final rule:

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

The -I only tells the compiler where header files are, the linker needs libraries and you use -L for that.

一抹苦笑 2024-12-01 09:06:04

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

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

如果安装了库,那么它应该显示类似这样的内容:

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

或者它只会显示一个空行在

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文