0

I'm trying to compile this program:
http://lists.boost.org/boost-users/att-40895/telnet.cpp
on a mac with OS X 10.7.3.

I'm using this line to compile:

g++ -O3 telnet.cpp -o telnet

and I'm getting this error:

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

From my research so far what I've come up with is that I need to somehow link to the boost library. I don't know how to tell if it's properly installed. I downloaded brew and used

brew install boost

to install it.

Sorry if the format is wrong, this is my first post. Thanks for the help. Please let me know if I need to provide any additional information.

JuJoDi
  • 14,627
  • 23
  • 80
  • 126

2 Answers2

2

You forgot to link against the Boost libraries. Try:

g++ -O3 -o telnet telnet.cpp -lboost_system -lboost_thread
mavam
  • 12,242
  • 10
  • 53
  • 87
  • I have tried that, it gives me "ld: library not found for -lboost_system". How can I make sure it's installed correctly? – JuJoDi May 03 '12 at 14:51
  • So I tried g++ -O3 -o telnet telnet.cpp -lboost_system-mt -lboost_thread-mt and it cut the errors down to just "Undefined symbols for architecture x86_64: "telnet_client::~telnet_client()", referenced from: _main in cc0utM62.o ld: symbol(s) not found for architecture x86_64 collect 2: ld returned 1 exit status. Seems like I'm getting closer! – JuJoDi May 03 '12 at 14:59
  • GOT IT! I think I just spent too much time being frustrated yesterday and forgetting what I was doing. I had a destructor defined in the code because I thought it might solve the problem I took it out and compiled with the above and it worked. Sorry for the triple post ): – JuJoDi May 03 '12 at 15:11
0

you might need -l boost_thread-mt instead of -lboost_thread I have not looked at the code but this might be the case

gda2004
  • 718
  • 13
  • 32