找不到 -lboost_system 的库
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您缺少
-L/opt/local/lib
。您应该能够在 Makefile 中设置LDFLAGS
:当然,这是假设 Boost 库位于
/opt/local/lib
中。如果您在 Makefile 中不使用常用的
CXXFLAGS
和LDFLAGS
变量,则直接添加-L/opt/local/lib
你的最终规则:-I
只告诉编译器头文件在哪里,链接器需要库,你可以使用-L
来实现。You're missing a
-L/opt/local/lib
. You should be able to set theLDFLAGS
in your Makefile:This assumes that the Boost libraries are in
/opt/local/lib
of course.If you're not using the usual
CXXFLAGS
andLDFLAGS
variables in your Makefile, then add the-L/opt/local/lib
directly in your final rule:The
-I
only tells the compiler where header files are, the linker needs libraries and you use-L
for that.您可以尝试在系统中查找它,如下所示:
如果安装了库,那么它应该显示类似这样的内容:
或者它只会显示一个空行在
您的情况下,boost似乎安装在另一个地方,因此需要额外的链接器信息,因此需要 -L 开关,如果你有它在 /usr/lib 中,因为我不需要 makefile 中的额外信息
You could try to look for it in your system like this :
if the library is installed, then it should show something like this:
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