0

Trying to get boost libraries setup and compile/run some of the boost tutorials but am running into issues. I've googled around and tried some things, but nothing seems to be working. Would appreciate it if you guys could point me in the right direction.

Here's output from command line:

g++ -I /usr/local/boost_1_68_0/ timer.cpp -o timer /tmp/ccLjn1qn.o: In function boost::system::system_category()': timer.cpp:(.text._ZN5boost6system15system_categoryEv[_ZN5boost6system15system_categoryEv]+0x7): undefined reference toboost::system::detail::system_category_instance' /tmp/ccLjn1qn.o: In function boost::system::generic_category()': timer.cpp:(.text._ZN5boost6system16generic_categoryEv[_ZN5boost6system16generic_categoryEv]+0x7): undefined reference toboost::system::detail::generic_category_instance' /tmp/ccLjn1qn.o: In function boost::asio::detail::posix_event::posix_event()': timer.cpp:(.text._ZN5boost4asio6detail11posix_eventC2Ev[_ZN5boost4asio6detail11posix_eventC5Ev]+0x4d): undefined reference topthread_condattr_setclock' /tmp/ccLjn1qn.o: In function boost::asio::detail::posix_thread::~posix_thread()': timer.cpp:(.text._ZN5boost4asio6detail12posix_threadD2Ev[_ZN5boost4asio6detail12posix_threadD5Ev]+0x26): undefined reference topthread_detach' /tmp/ccLjn1qn.o: In function boost::asio::detail::posix_thread::join()': timer.cpp:(.text._ZN5boost4asio6detail12posix_thread4joinEv[_ZN5boost4asio6detail12posix_thread4joinEv]+0x2b): undefined reference topthread_join' /tmp/ccLjn1qn.o: In function boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> >::basic_waitable_timer(boost::asio::io_context&, std::chrono::duration<long, std::ratio<1l, 1000000000l> > const&)': timer.cpp:(.text._ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEEC2ERNS0_10io_contextERKNS2_8durationIlSt5ratioILl1ELl1000000000EEEE[_ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEEC5ERNS0_10io_contextERKNS2_8durationIlSt5ratioILl1ELl1000000000EEEE]+0x41): undefined reference toboost::system::detail::system_category_instance' /tmp/ccLjn1qn.o: In function boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> >::wait()': timer.cpp:(.text._ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEE4waitEv[_ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEE4waitEv]+0x26): undefined reference toboost::system::detail::system_category_instance' /tmp/ccLjn1qn.o: In function boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> > >::destroy(boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> > >::implementation_type&)': timer.cpp:(.text._ZN5boost4asio6detail22deadline_timer_serviceINS1_18chrono_time_traitsINSt6chrono3_V212steady_clockENS0_11wait_traitsIS6_EEEEE7destroyERNSA_19implementation_typeE[_ZN5boost4asio6detail22deadline_timer_serviceINS1_18chrono_time_traitsINSt6chrono3_V212steady_clockENS0_11wait_traitsIS6_EEEEE7destroyERNSA_19implementation_typeE]+0x29): undefined reference toboost::system::detail::system_category_instance' collect2: error: ld returned 1 exit status

rich
  • 11
  • 4
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Miles Budnek Aug 28 '18 at 15:44

1 Answers1

1

You need to learn about linking libraries (like -l boost_system -l boost_thread -l boost_asio). Boost documentation should have usage examples.

nurettin
  • 11,090
  • 5
  • 65
  • 85
  • I have tried linking libraries and was still have issues. After some more searching I got the timer.cpp compile, but when I go to run it fails. > $ g++ -I /usr/local/boost_1_68_0/ timer.cpp -o timer -l boost_system -lpthread $ ./timer ./timer: error while loading shared libraries: libboost_system.so.1.68.0: cannot open shared object file: No such file or directory – rich Aug 28 '18 at 16:28
  • For the record: your shared objects are not found in `ld` (linker) path. That means you need to install the library so that it becomes generally available, or you need to set `LD_LIBRARY_PATH` to include your shared object's directory before running your executable that depends on it. – nurettin Jan 03 '21 at 06:57