views:

995

answers:

2

Just asked a question about linking Boost libraries in the make file. Thanks to those who helped with that. I ended up with this:

accesstimer: acctime.o bentimer.o
    g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_system -lboost_filesystem   acctime.o bentimer.o -o accesstimer   

acctime.o: acctime.cpp bentimer.h
    g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp 

bentimer.o: bentimer.cpp bentimer.h
    g++ -c bentimer.cpp 

My problem now is that boost.filesystem requires boost.system and the above make file can't find boost.system.

I got the name for boost.filesystem by looking in the stage/lib dir and removing the lib and trailing section of the file name (libboost_filesystem-gcc41-mt.a). As you can see above I've done the same with libboost_system-gcc41-mt.a and come up with boost_system but it can't be found.

Does anyone know how I would link boost.system?

Thanks Uncle zeive, that's worked but as soon as I try to use one of the filesystem keywords (e.g. exists) I get this:

g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp
In file included from acctime.cpp:5:
bentimer.h:2:19: warning: extra tokens at end of #ifndef directive
bentimer.h:11:18: warning: extra tokens at end of #ifdef directive
bentimer.h:28:3: warning: no newline at end of file
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_system-gcc41-mt -lboost_filesystem   acctime.o bentimer.o -o accesstimer
acctime.o: In function `boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
acctime.cpp:(.text._ZN5boost10filesystem6existsINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EEbE4typeERKS7_[boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)]+0x35): undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::system::error_code&)'
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1

Do you know wjat I'm doing wrong here?

Now I've added the -I boost root link to the first link command it builds fine:

accesstimer: acctime.o bentimer.o
    g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_system-gcc41-mt -lboost_filesystem-gcc41-mt  -I /usr/local/boost/boost_1_39_0 acctime.o bentimer.o -o accesstimer     

acctime.o: acctime.cpp bentimer.h
    g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp 

bentimer.o: bentimer.cpp bentimer.h
    g++ -c bentimer.cpp 

But when I execute I get:

./accesstimer: error while loading shared libraries: libboost_system-gcc41-mt-1_39.so.1.39.0: cannot open shared object file: No such file or directory

That file is present but its not picking it up.

+3  A: 

Actually you shouldn't remove the entire trailing part, only the extension:

-lboost_system-gcc41-mt

The same goes for boost_filesystem:

-lboost_filesystem-gcc41-mt
UncleZeiv
-lboost_filesystem works just fine for me.
Robert Massaioli
@Robert: that probably means that you have a `libboost_filesystem.so` symbolic link installed in your library path, but most of the time that link isn't there as you want to make sure you are using the same compiler etc., hence the longer libname.
UncleZeiv
Fair enough...and it seems that you are right. Thankyou Ubuntu symlink.
Robert Massaioli
+1  A: 

The answer for me, hopefully it'll help someone else was as follows: I was having problems linking, the good folk on here got me putting the right stuff in my make file but I was still getting:

./accesstimer: error while loading shared libraries: libboost_system-gcc41-mt-1_39.so.1.39.0: cannot open shared object file: No such file or directory

The solution was to just execute:

ldconfig

On my Linux machine that I had just installed Boost on and built the filesytem libraries. I am assuning that since ldconfig needed to be run for my system to pick up the new libraries I had installed. It now works.

Columbo