2012-05-02 80 views
0

我想编译这个程序:
http://lists.boost.org/boost-users/att-40895/telnet.cpp
与OS X 10.7.3的Mac。麻烦编制的telnet升压例如

我使用这行编译:

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 

要安装它。

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

+0

看一看[这](HTTP的情况://计算器.com/questions/5820269/c-boost-undefined-symbols-in-example) –

回答

2

你忘了链接到Boost库。尝试:

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

我试过了,它给了我“ld:library not-for -lboost_system”。我怎样才能确保它的安装正确? – JuJoDi

+0

所以我尝试了g ++ -O3 -o telnet telnet.cpp -lboost_system-mt -lboost_thread-mt,它将错误降低到“未定义的架构x86_64符号:”telnet_client ::〜telnet_client()“,引用来自:_main在cc0utM62.o ld:symbol(s)not found for architecture x86_64 collect 2:ld returned 1 exit status。好像我越来越接近了! – JuJoDi

+0

GOT IT!我想我只是花了太多的时间在昨天沮丧,忘记了什么我在做,我在代码中定义了一个析构函数,因为我认为它可以解决我拿出来并用上面的代码进行编译的问题,并且工作正常。 – JuJoDi

0

您可能需要-l boost_thread-MT,而不是-lboost_thread我没有看过的代码,但是这可能是