促进图书馆链接问题

Boost Libraries Linking Issues

本文关键字:问题 链接 图书馆      更新时间:2023-10-16

我在链接boost库时遇到了一些问题。我正在尝试执行简单的定时器程序

但当我执行程序时,错误低于

~/boost_1_48_0/boost/asio/detail/impl/posix_tss_ptr.ipp:34: undefined reference to `pthread_key_create'
./timer.o: In function `~posix_tss_ptr': /~/boost_1_48_0/boost/asio/detail/posix_tss_ptr.hpp:48: undefined reference to `pthread_key_delete' 
./timer.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service, boost::asio::detail::task_io_service::thread_info>::context>::operator boost::asio::detail::call_stack<boost::asio::detail::task_io_service, boost::asio::detail::task_io_service::thread_info>::context*() const': ~/boost_1_48_0/boost/asio/detail/posix_tss_ptr.hpp:54: undefined reference to `pthread_getspecific'
./timer.o: In function `~posix_tss_ptr': ~/boost_1_48_0/boost/asio/detail/posix_tss_ptr.hpp:48: undefined reference to `pthread_key_delete' collect2: ld returned 1 exit status

我已包含_I ~/boost_1_48_0/ -L ~/boost_1_48_0/stage/lib -lboost-system

有什么快速的建议吗?

您还记得指定-pthread吗?来自GCC手册页:

   -pthread
       Add support for multithreading using the POSIX threads library.
       This option sets flags for both the preprocessor and linker.

它是使用POSIX线程的代码所必需的。