So I'm trying to compile and run a simple boost timer program
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
int main() {
using namespace boost::asio;
io_service io;
deadline_timer t(io, boost::posix_time::seconds(5));
t.wait();
std::cout << "Hello World!" << std::endl;
return 0;
}
The first thing I tried when compiling this program was to do
g++ -I /home/vagrant/boost_1_60_0 main.cpp
which gave me an error of
/tmp/cc8Ytqko.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0xfc): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x108): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x114): undefined reference to `boost::system::system_category()'
/tmp/cc8Ytqko.o: In function `boost::system::error_code::error_code()':
main.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/cc8Ytqko.o: In function `boost::asio::error::get_system_category()':
main.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status
So then I did some research and it seems I needed to build the boost_system binaries so I went to directory boost was located in and ran
./bootstrap.sh
./b2 --with-system
Then I compiled again
g++ -I /home/vagrant/boost_1_60_0 main.cpp -L/home/vagrant/boost_1_60_0/stage/lib/ -lboost_system
and this didn't give me any error but when I ran the executable
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./a.out
./a.out: error while loading shared libraries: libboost_system.so.1.60.0: cannot open shared object file: No such file or directory
Don't really know what I need to do here
liibboost_system.so.1.60.0
cannot be found in the list of directories searched by the dynamic linker. The non-default shared-object location is not stored in the binary by default. The environment variable LD_LIBRARY_PATH
can be used to add directories that will be searched before the standard locations:
LD_LIBRARY_PATH=/home/vagrant/boost_1_60_0/stage/lib/ ./a.out
This will only work for the current bash environment, and there are also ways to store the path in the executable so that the environment variable is not needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With