2012-05-02 25 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我沒有看過的代碼,但是這可能是