没有找到-lboost_system的库
library not found for -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
在学校的解决方案是使用-lboostrongystem作为g++的参数,但现在我已经把项目带回家了我的mac,这不起作用。我认为这主要是因为在学校时,boost文件位于usr/local/lib(或类似的地方)。
当我添加-lboostrongystem参数时,我得到以下消息
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标志来修复它,这对我不起作用。
帮助!谢谢!
您缺少一个-L/opt/local/lib
。您应该能够在Makefile中设置LDFLAGS
:
LDFLAGS=-L/opt/local/lib
这里假设Boost库在/opt/local/lib
中。
如果您没有在Makefile中使用通常的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
。
您可以尝试在您的系统中查找它,像这样:
/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
相关文章:
- C/C++编译器通常会删除重复的库吗
- 如何将C++中的库和头与MinGW一起使用
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 构建一个由C和C++文件组成的库
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- 为重写std::exception的库生成swig接口时出错
- 我可以在 Arduino 的库文件夹之外安装库吗?
- 我希望定义两个具有相同代码的不同名称的库
- 运行命令 "rosbag play example.bag" 时出错。找不到与插件 rosbag/NoEncryptor 对应的库
- 更新后的Android Studio现在需要Clang,不再链接到GCC的库
- 包括没有完整路径的我的库
- 如何允许编译器查找通过 brew 安装的库
- 以现代 CMake 方式控制包含的库中的构建选项(测试等)
- 从 CMake 中的库目录加载共享库?
- Windows (COM) API 的行为不同,没有特定的库
- 如何使用我构建的库,而不会从源代码出错,但不为我自己的项目编译?
- 如何编译使用从不同编译器编译的库的应用程序?
- OS X: ld: 找不到 -lstdc++ 的库
- Debian Buster 中的库不匹配?
- 找不到 CMake 链接的库