library not found for -lboost_system

时光总嘲笑我的痴心妄想 提交于 2019-11-30 03:12:14

问题


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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6721559/library-not-found-for-lboost-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!