簡體   English   中英

C++ / Boost:示例中的未定義符號?

[英]C++ / Boost: Undefined Symbols in example?

我嘗試編譯的示例來自: 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
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 安裝正確。 我有另一個應用程序使用了一些提升位功能。

更新:這是我正在使用的當前命令:

% 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++ 升壓庫以與 usins -l 選項鏈接。 我快速瀏覽了這個示例,並猜測您肯定需要thread庫。 您可以使用它與它鏈接

g++ source.cpp -o executable -lboost_thread 

您也可能需要使用 boost_system 庫

g++ source.cpp -o executable -lboost_thread -lboost_system

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM