boost中g++ 鏈接undefined reference to `boost::system::generic_category()問題


編譯錯誤如下:

g++ -std=c++11  tcp_session.cpp tcp_server.cpp test.cpp -o test -pthread
/tmp/ccv4rZkD.o: In function `__static_initialization_and_destruction_0(int, int)':
tcp_session.cpp:(.text+0x670): undefined reference to `boost::system::generic_category()'
tcp_session.cpp:(.text+0x67c): undefined reference to `boost::system::generic_category()'
tcp_session.cpp:(.text+0x688): undefined reference to `boost::system::system_category()'
/tmp/ccv4rZkD.o: In function `boost::system::error_code::error_code()':
tcp_session.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/ccv4rZkD.o: In function `boost::asio::error::get_system_category()':
tcp_session.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/cctVI799.o: In function `tcp_server::start_accept()':
tcp_server.cpp:(.text+0x18e): undefined reference to `tcp_session::socket()'
/tmp/cctVI799.o: In function `__static_initialization_and_destruction_0(int, int)':
tcp_server.cpp:(.text+0x2fc): undefined reference to `boost::system::generic_category()'
tcp_server.cpp:(.text+0x308): undefined reference to `boost::system::generic_category()'
tcp_server.cpp:(.text+0x314): undefined reference to `boost::system::system_category()'
/tmp/cctVI799.o: In function `boost::thread_exception::thread_exception(int, char const*)':
tcp_server.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x23): undefined reference to `boost::system::system_category()'
/tmp/cctVI799.o: In function `boost::condition_error::condition_error(int, char const*)':

添加鏈接庫  -lboost_system, 問題解決。

若還有其他查找不到的,可以去安裝路徑,查找相應的庫文件,編譯時加載。

eg:

/home/program/boost_1_67_0$ find . -name *.so
./stage/lib/libboost_log_setup.so
./stage/lib/libboost_chrono.so
./stage/lib/libboost_numpy27.so
./stage/lib/libboost_coroutine.so
./stage/lib/libboost_atomic.so
./stage/lib/libboost_type_erasure.so
./stage/lib/libboost_serialization.so
./stage/lib/libboost_math_c99f.so
./stage/lib/libboost_regex.so
./stage/lib/libboost_container.so
./stage/lib/libboost_filesystem.so
./stage/lib/libboost_thread.so
./stage/lib/libboost_math_tr1l.so
./stage/lib/libboost_random.so
./stage/lib/libboost_program_options.so
./stage/lib/libboost_signals.so
./stage/lib/libboost_locale.so
./stage/lib/libboost_unit_test_framework.so
./stage/lib/libboost_wave.so
./stage/lib/libboost_stacktrace_backtrace.so
./stage/lib/libboost_date_time.so
./stage/lib/libboost_iostreams.so
./stage/lib/libboost_stacktrace_addr2line.so
./stage/lib/libboost_log.so
./stage/lib/libboost_stacktrace_noop.so
./stage/lib/libboost_math_c99.so
./stage/lib/libboost_prg_exec_monitor.so
./stage/lib/libboost_math_c99l.so
./stage/lib/libboost_graph.so
./stage/lib/libboost_timer.so
./stage/lib/libboost_stacktrace_basic.so
./stage/lib/libboost_python27.so
./stage/lib/libboost_context.so
./stage/lib/libboost_math_tr1f.so
./stage/lib/libboost_math_tr1.so
./stage/lib/libboost_system.so
./stage/lib/libboost_wserialization.so
./stage/lib/libboost_contract.so

例如,線程相關,  -lboost_thread

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM