[英]C++ / Boost: Undefined Symbols in example?
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)我尝试编译的示例来自: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html (聊天示例)
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
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说找不到 -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 =\我查看了 opt/local/lib (安装了 boost),我没有看到任何 libboost_asio.so 或类似的东西=\
You need to provide g++ boost libraries to link with usins -l option.您需要提供 g++ 升压库以与 usins -l 选项链接。 I have a quick look on this examples and guess that you definitly need
thread
library.我快速浏览了这个示例,并猜测您肯定需要
thread
库。 You can link with it using您可以使用它与它链接
g++ source.cpp -o executable -lboost_thread
Also you may need with boost_system library using您也可能需要使用 boost_system 库
g++ source.cpp -o executable -lboost_thread -lboost_system
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.