I am on Ubuntu 16.04 LTS, and I have g++ working and have downloaded boost a few minutes ago.
I have a very simple cpp file that has #include <boost/thread.hpp>
in it. Compiling (running g++ -c -std=c++11 simple.cpp -o simple.o
) works, however, linking won't. I tried the following options:
g++ -std=c++11 -lpthread -lboost_system-lboost_thread simple.o -o simple
g++ -std=c++11 -L/usr/bin -L/usr/lib -I/usr/include -lpthread -lboost_system-lboost_thread simple.o -o simple
One thing worthy of mentioning is that /usr/include/boost
exists while /usr/lib/boost
does not.
I have installed boost using: sudo apt-get install libboost-all-dev
The error I get upon linking is:
simple.o: In function `__static_initialization_and_destruction_0(int, int)':
simple.cpp:(.text+0x132): undefined reference to `boost::system::generic_category()'
simple.cpp:(.text+0x13e): undefined reference to `boost::system::generic_category()'
simple.cpp:(.text+0x14a): undefined reference to `boost::system::system_category()'
simple.o: In function `boost::thread_exception::thread_exception(int, char const*)':
simple.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x23): undefined reference to `boost::system::system_category()'
simple.o: In function `boost::detail::thread_data_base::thread_data_base()':
simple.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]+0x1e): undefined reference to `vtable for boost::detail::thread_data_base'
simple.o: In function `boost::thread::start_thread()':
simple.cpp:(.text._ZN5boost6thread12start_threadEv[_ZN5boost6thread12start_threadEv]+0x24): undefined reference to `boost::thread::start_thread_noexcept()'
simple.o: In function `boost::thread::~thread()':
simple.cpp:(.text._ZN5boost6threadD2Ev[_ZN5boost6threadD5Ev]+0x14): undefined reference to `boost::thread::detach()'
simple.o: In function `boost::thread::get_id() const':
simple.cpp:(.text._ZNK5boost6thread6get_idEv[_ZNK5boost6thread6get_idEv]+0x18): undefined reference to `boost::thread::native_handle()'
simple.o: In function `boost::thread::join()':
simple.cpp:(.text._ZN5boost6thread4joinEv[_ZN5boost6thread4joinEv]+0x88): undefined reference to `boost::thread::join_noexcept()'
simple.o: In function `Task::operator()()':
simple.cpp:(.text._ZN4TaskclEv[_ZN4TaskclEv]+0x67): undefined reference to `boost::this_thread::yield()'
simple.o: In function `boost::detail::thread_data<Task>::~thread_data()':
simple.cpp:(.text._ZN5boost6detail11thread_dataI4TaskED2Ev[_ZN5boost6detail11thread_dataI4TaskED5Ev]+0x20): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
simple.o:(.rodata._ZTIN5boost6detail11thread_dataI4TaskEE[_ZTIN5boost6detail11thread_dataI4TaskEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
Aucun commentaire:
Enregistrer un commentaire