C++ / Boost: Undefined Symbols in example?(C++/Boost:示例中的未定义符号?)
问题描述
我试图编译的例子来自:http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html(聊天例子)
这是我用来制作它的:
<预><代码>>>>g++ chat_client.cpp chat_message.hpp>>>g++ chat_server.cpp chat_message.hpp这是终端输出的内容:
% g++ chat_client.cpp chat_message.hpp在 chat_client.cpp:17 包含的文件中:chat_message.hpp:在成员函数‘void chat_message::encode_header()’中:chat_message.hpp:84: 警告:格式%4d"需要类型int",但参数 3 的类型为size_t"ld:警告:在 chat_message.hpp 中,文件是为不受支持的文件格式构建的,这不是所链接的体系结构 (x86_64)未定义符号:boost::system::generic_category()",引用自:__static_initialization_and_destruction_0(int, int)in cctJA2c1.o__static_initialization_and_destruction_0(int, int)in cctJA2c1.oboost::thread::start_thread()",引用自:boost::thread::thread, boost::_bi::list1>>>(boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >, boost::disable_if, boost::_bi::list1, boost::_bi::list1>>>在cctJA2c1.o中"vtable for boost::detail::thread_data_base",引用自:boost::detail::thread_data_base::thread_data_base() 在 cctJA2c1.oboost::thread::~thread()",引用自:_main 在 cctJA2c1.o_main 在 cctJA2c1.oboost::detail::thread_data_base::~thread_data_base()",引用自:boost::detail::thread_data, boost::_bi::list1>>>::~thread_data() 在 cctJA2c1.o 中boost::detail::thread_data, boost::_bi::list1>>>::~thread_data() 在 cctJA2c1.o 中boost::system::system_category()",引用自:cctJA2c1.o 中的 boost::system::get_system_category()cctJA2c1.o 中的 boost::system::error_code::error_code()__static_initialization_and_destruction_0(int, int)in cctJA2c1.old:未找到符号collect2: ld 返回 1 个退出状态
- Boost 安装正确.我有另一个应用,它使用了一些 boosts 位功能.
更新:这是我正在使用的当前命令:
% g++ chat_client.cpp chat_message.hpp -lboost_asio -lboost_thread -o client -L/opt/local/lib/
说它找不到 -lboost_asio
我查看了 opt/local/lib(安装了 boost 的地方),但我没有看到任何 libboost_asio.so 或类似的东西 =
您需要提供 g++ boost 库以与 usins -l 选项链接.我快速浏览了这个示例,并猜测您肯定需要 thread
库.您可以使用
g++ source.cpp -o 可执行文件 -lboost_thread
你也可能需要使用
的 boost_system 库g++ source.cpp -o 可执行文件 -lboost_thread -lboost_system
The example I'm trying to compile is from: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html (the chat example)
Here is what I'm using to make it:
>>> g++ chat_client.cpp chat_message.hpp
>>> g++ chat_server.cpp chat_message.hpp
This is what the terminal outputs:
% g++ chat_client.cpp chat_message.hpp
In file included from chat_client.cpp:17:
chat_message.hpp: In member function ‘void chat_message::encode_header()’:
chat_message.hpp:84: warning: format ‘%4d’ expects type ‘int’, but argument 3 has type ‘size_t’
ld: warning: in chat_message.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols:
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in cctJA2c1.o
__static_initialization_and_destruction_0(int, int)in cctJA2c1.o
"boost::thread::start_thread()", referenced from:
boost::thread::thread<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >(boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >, boost::disable_if<boost::is_convertible<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >&, boost::detail::thread_move_t<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > > >, boost::thread::dummy*>::type)in cctJA2c1.o
"boost::thread::join()", referenced from:
_main in cctJA2c1.o
"typeinfo for boost::detail::thread_data_base", referenced from:
typeinfo for boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >in cctJA2c1.o
"vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base()in cctJA2c1.o
"boost::thread::~thread()", referenced from:
_main in cctJA2c1.o
_main in cctJA2c1.o
"boost::detail::thread_data_base::~thread_data_base()", referenced from:
boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::~thread_data()in cctJA2c1.o
boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::~thread_data()in cctJA2c1.o
"boost::system::system_category()", referenced from:
boost::system::get_system_category() in cctJA2c1.o
boost::system::error_code::error_code()in cctJA2c1.o
__static_initialization_and_destruction_0(int, int)in cctJA2c1.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
- Boost is installed correctly. I have another app that uses a couple of boosts bit features.
UPDATE: this is the current command I'm using:
% g++ chat_client.cpp chat_message.hpp -lboost_asio -lboost_thread -o client -L/opt/local/lib/
says it can't find -lboost_asio
I looked in opt/local/lib (where boost is installed) and I don't see any libboost_asio.so or anything like that =
You need to provide g++ boost libraries to link with usins -l option. I have a quick look on this examples and guess that you definitly need thread
library. You can link with it using
g++ source.cpp -o executable -lboost_thread
Also you may need with boost_system library using
g++ source.cpp -o executable -lboost_thread -lboost_system
这篇关于C++/Boost:示例中的未定义符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++/Boost:示例中的未定义符号?
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01