-lboost_system找不到库 [英] library not found for -lboost_system
问题描述
我使用macports安装了boost。文件似乎在/ opt / local / include / boost /
我的makefile不再工作,我收到以下错误
未定义符号:
boost :: system :: generic_category(),引用自:
__static_initialization_and_destruction_0(int,int) .o
__static_initialization_and_destruction_0(int,int)in client.o
boost :: system :: system_category(),引用自:
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发现
collect2:ld返回1退出状态
make:*** [client]错误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:未找到-lboost_system的库库
collect2:ld返回1退出状态
make:*** [client]错误1
我已经尝试了一些变体使用-L和-l,但我似乎找不到一个组合工作。在学校我也不必使用-L。我在这里读了一些其他类似的问题的帖子,但他们通过添加-l标志,它不为我工作固定它。
帮助!感谢!
您缺少一个 -L / opt / local / lib
。您应该能够在Makefile中设置 LDFLAGS
:
LDFLAGS = -L / opt / local / lib
这假设Boost库在 / opt / local / lib
当然。
如果你不使用通常的
CXXFLAGS 和 LDFLAGS
变量,然后直接添加 -L / opt / local / lib
在您的最终规则中: client:client.o Packet.o
g ++ -L / opt / local / lib -o client client.o Packet.o -lboost_system
-I
只告诉编译器头文件在哪里,链接器需要库,你使用 -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!
解决方案 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.
这篇关于-lboost_system找不到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!