编译远程网提升示例时遇到问题

Trouble compiling telnet boost example

本文关键字:遇到 问题 程网提 编译      更新时间:2023-10-16

我正在尝试编译这个程序:

http://lists.boost.org/boost-users/att-40895/telnet.cpp在装有 OS X 10.7.3 的 Mac 上。

我正在使用这一行来编译:

g++ -O3 telnet.cpp -o telnet

我收到此错误:

Undefined symbols for architecture x86_64:
  "boost::system::generic_category()", referenced from:
  global constructors keyed to _ZN12_GLOBAL__N_12_1Ein cc4A3W1S.o
  "boost::system::system_category()", referenced from:
  global constructors keyed to _ZN12_GLOBAL__N_12_1Ein cc4A3W1S.o
   boost::asio::detail::posix_thread::func<boost::asio::detail::resolver_service_base::work_io_service_runner>::run()in cc4A3W1S.o
  boost::asio::detail::reactive_socket_connect_op_base::do_perform(boost::asio::detail::reactor_op*)in cc4A3W1S.o
  boost::asio::detail::socket_ops::translate_netdb_error(int) in cc4A3W1S.o
  boost::asio::ip::basic_resolver_iterator<boost::asio::ip::tcp>::create(addrinfo*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in cc4A3W1S.o
  boost::asio::detail::socket_ops::translate_addrinfo_error(int) in cc4A3W1S.o
  boost::asio::detail::kqueue_reactor::run(bool, boost::asio::detail::op_queue<boost::asio::detail::task_io_service_operation>&)in cc4A3W1S.o
  ...
"vtable for boost::detail::thread_data_base", referenced from:
  boost::detail::thread_data_base::thread_data_base()in cc4A3W1S.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"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 cc4A3W1S.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 cc4A3W1S.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 cc4A3W1S.o
"boost::thread::join()", referenced from:
  _main in cc4A3W1S.o
"boost::thread::~thread()", referenced from:
  _main in cc4A3W1S.o
"telnet_client::~telnet_client()", referenced from:
  _main in cc4A3W1S.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 cc4A3W1S.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

从我迄今为止的研究来看,我想出的是我需要以某种方式链接到提升库。 我不知道如何判断它是否正确安装。 我下载了brew并使用

brew install boost

来安装它。

对不起,如果格式错误,这是我的第一篇文章。 感谢您的帮助。如果我需要提供任何其他信息,请告诉我。

您忘记链接到 Boost 库。尝试:

g++ -O3 -o telnet telnet.cpp -lboost_system -lboost_thread

您可能需要 -l boost_thread-mt 而不是 -lboost_thread 我没有看过代码,但可能是这种情况