Problem when using Boost.Asio at Fedora 11

Hi all, I'm new at C++ and Boost and I'm with some problems when I try to use Boost.Asio library. I was trying to build the first example from Boost.Asio's tutorial. The code is like this: ===== CODE ===== #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> int main( int argc, char **argv ) { boost::asio::io_service io; boost::asio::deadline_timer t(io, boost::posix_time::seconds(5)); t.wait(); std::cout << "Opa !" << std::endl; return 0; } ===== CODE ===== I'm trying to compile using this command: g++ -I/usr/include/boost/ example.cpp -o example", and I'm getting this error: ==== ERROR ==== /tmp/ccv68fST.o: In function `__static_initialization_and_destruction_0(int, int)': timer.cpp:(.text+0x51): undefined reference to `boost::system::get_system_category()' timer.cpp:(.text+0x5b): undefined reference to `boost::system::get_generic_category()' timer.cpp:(.text+0x65): undefined reference to `boost::system::get_generic_category()' timer.cpp:(.text+0x6f): undefined reference to `boost::system::get_generic_category()' timer.cpp:(.text+0x79): undefined reference to `boost::system::get_system_category()' /tmp/ccv68fST.o: In function `boost::asio::error::get_system_category()': timer.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x7): undefined reference to `boost::system::get_system_category()' /tmp/ccv68fST.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service<boost::asio::detail::epoll_reactor<false>
::context>::~posix_tss_ptr()': timer.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceINS1_13epoll_reactorILb0EEEEEE7contextEED2Ev[boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service<boost::asio::detail::epoll_reactor<false> ::context>::~posix_tss_ptr()]+0xf): undefined reference to `pthread_key_delete' /tmp/ccv68fST.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service<boost::asio::detail::epoll_reactor<false> ::context>::posix_tss_ptr()': timer.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceINS1_13epoll_reactorILb0EEEEEE7contextEEC2Ev[boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service<boost::asio::detail::epoll_reactor<false> ::context>::posix_tss_ptr()]+0x22): undefined reference to `pthread_key_create' collect2: ld returned 1 exit status ==== ERROR ====
I already installed Boost and Boost-devel packages. Does anyone know what is missing ? Thanks, -- Davi Vercillo C. Garcia B.Sc. Student - DCC-IM/UFRJ Fedora Project Contributor http://davivercillo.fedorapeople.org/ "If a million people say a foolish thing, it is still a foolish thing." - Anatole France

On Wednesday 26 August 2009 20:50:02 Davi Vercillo C. Garcia wrote:
I'm trying to compile using this command: g++ -I/usr/include/boost/ example.cpp -o example", and I'm getting this error:
[snip] You need to specify the correct libraries (like so): g++ -pthread -o example example.cc -lboost_system -lboost_date_time Regards, Ravi

Hi,
You need to specify the correct libraries (like so): g++ -pthread -o example example.cc -lboost_system -lboost_date_time
Thanks, it worked !!! One more question, How can I know the correct names of these libraries ? Bye, -- Davi Vercillo C. Garcia B.Sc. Student - DCC-IM/UFRJ Fedora Project Contributor http://davivercillo.fedorapeople.org/ "If a million people say a foolish thing, it is still a foolish thing." - Anatole France

Thanks, it worked !!! One more question, How can I know the correct names of these libraries ?
Simply look in corresponding lib folder and filter all libboost... files. Once you will meet similar errors in future, you will be able to determine what library you need to link.

Hi,
Simply look in corresponding lib folder and filter all libboost... files. Once you will meet similar errors in future, you will be able to determine what library you need to link.
Ok ! Thanks, -- Davi Vercillo C. Garcia B.Sc. Student - DCC-IM/UFRJ Fedora Project Contributor http://davivercillo.fedorapeople.org/ "If a million people say a foolish thing, it is still a foolish thing." - Anatole France
participants (3)
-
Davi Vercillo C. Garcia
-
Ravi
-
Roman Shmelev