2017-04-15 1 views
0

나는이 라이브러리를 배우려고하고 있으며 공식 튜토리얼에서 간단한 프로그램을 컴파일하는 데 어려움을 겪고있다.정의되지 않은 참조를 부스트하기

우분투 16.04LTS를 통해 설치 부스트 :

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; 
} 

컴파일 명령을

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 

답변

0

당신의 컴파일 명령 (g ++에 이러한 플래그를 추가 clang) :

-lboost_system -lboost_filesystem 
+0

고맙습니다. –

+0

어떤 라이브러리를 링크해야하는지 배우려면 어디로 가야합니까? 또한 왜이 기능이 작동하지 않습니까? g ++ -l boost_system -l boost_filesystem test.cpp l과 boost_ * 사이의 공백을 삭제해야하는 이유는 무엇입니까? –

+0

@AranBins Google it! –

관련 문제