Including boost libraries in makefiles

I am learning Boost and am having problems with my files. Here is my main make file:

accesstimer: acctime.o btimer.o
    g++ acctime.o btimer.o -o accesstimer

acctime.o: acctime.cpp btimer.h
    g++ -c acctime.cpp 

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

When acctime.cpp has no boost file system elements, in this m file, ake works fine. As soon as I add boost file system elements, I obviously have to make references to boost libray in the make file, where I am having problems.

The following line works to compile a single file:

g++ -I /usr/local/boost/boost_1_39_0 boosttest1.cpp -o bt1 /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a

Now I'm trying to integrate this into a makefile. I tried a lot, based on what information I can find on the Internet, but no one works, this is my last:

accesstimer: acctime.o bentimer.o
    g++ acctime.o bentimer.o -o accesstimer

acctime.o: acctime.cpp bentimer.h
    g++ -c -I /usr/local/boost/boost_1_39_0 acctime.cpp /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a

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

Unfortunately stlill cannot find Boost libraries, can anyone help? thanks

After reading the advice of the people who answered, I got the following:

accesstimer: acctime.o bentimer.o
    g++ -L /usr/local/boost/boost_1_39_0 acctime.o /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a bentimer.o -o accesstimer

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

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

But it is still not connected.

This is the error message I get:

g++ -L /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a 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&)]+0x26): undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&)'
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1

orsogufo (! ), :

accesstimer: acctime.o bentimer.o
    g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer  

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

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

, :

g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt.a
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1

, : /usr/local/boost/boost _1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a

, :

accesstimer: acctime.o bentimer.o
    g++  -L/usr/local/boost/boost_1_39_0 -lboost_filesystem-gcc41-mt 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 

:

g++  -L/usr/local/boost/boost_1_39_0/stage/lib/ -llibboost_filesystem-gcc41-mt acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1

:

accesstimer: acctime.o bentimer.o
    g++ -L/usr/local/boost/boost_1_39_0/stage/lib -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 

+5
3

EDITED
( makefile), boost -L -l.

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

/usr/local/boost/boost_1_39_0/stage/lib - , , boost_filesystem lib ( ).

.a, , ... .

+9

boost ( ), ( ).

+2

. boost cmake/make. cpp.

boost Makefile, ( -L) ( -l).

-L //the/libraries -l library

** , **

:

  • $locate boost > libboost.txt

    $gedit libboost.txt

  • , boost.

  • ( "ctr + F" ) libboost, boost .a .so .

  • , .so.

    : .so /usr/lib/x86_64-linux-gnu/libboost_filesystem.so

    : -L/usr/lib/x86_64-linux-gnu/

, ?

  • , /

    , : ,

    libboost_filesystem.so

    libboost_thread.so

    libboost_system.so

  • : -l:

    -l lboost_filesystem

    -l lboost_thread

    -l lboost_system

I hope this helps you, if you find it easier, please

0
source

All Articles