2017-04-15 4 views
0

Ich versuche, die Boost-Bibliothek zu lernen, und ich habe Probleme, sogar ein einfaches Programm aus ihren offiziellen Tutorials zu kompilieren.Boost nicht definierte Referenzen

Ubuntu 16.04LTS, installiert Schub über:

sudo apt-get install libboost-all-dev 

test.cpp:

#include <iostream> 
#include <boost/asio.hpp> 
#include <boost/date_time/posix_time/posix_time.hpp> 

int main() 
{ 
    boost::asio::io_service io; 
    boost::asio::deadline_timer t(io, boost::posix_time::seconds(5)); 
    t.wait(); 
    std::cout << "Hello, world!" << std::endl; 

    return 0; 
} 

Kompilierungsbefehl:

g++ -l boost_system test.cpp 
/tmp/ccFqTvqW.o: In function `__static_initialization_and_destruction_0(int, int)': 
test.cpp:(.text+0x11f): undefined reference to `boost::system::generic_category()' 
test.cpp:(.text+0x12b): undefined reference to `boost::system::generic_category()' 
test.cpp:(.text+0x137): undefined reference to `boost::system::system_category()' 
/tmp/ccFqTvqW.o: In function `boost::system::error_code::error_code()': 
test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()' 
/tmp/ccFqTvqW.o: In function `boost::asio::error::get_system_category()': 
test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()' 
collect2: error: ld returned 1 exit status 

Antwort

0

Fügen Sie diese Fahnen zu Ihrer Zusammenstellung Befehl (g ++ oder Klingeln):

-lboost_system -lboost_filesystem 
+0

Danke das funktioniert. –

+0

Wohin kann ich gehen, um zu erfahren, welche Bibliotheken ich verknüpfen muss? Und warum funktioniert das nicht? g ++ -l boost_system -l boost_filesystem test.cpp Warum muss ich den Abstand zwischen l und boost_ * löschen? –

+0

@AranBins Google es! –