2017-11-05 4 views
0

라이브러리를 C++ cmake 프로젝트에 연결하는 데 하루 종일 보냈습니다.`boost :: gregorian :: greg_month :: as_short_string() const '에 대한 정의되지 않은 참조를 작성하십시오.

따라서 cmake 3.4boost 1.61.0을 사용하고 있습니다.

void TestClass::getTime() { 
    this->endDate = boost::posix_time::second_clock::local_time(); 
} 

가 그럼 난 함수를 반환 문자열 endDate의 값을 반환 할 : 나는 함수 인 클래스가있는 지역의 시간이 소요됩니다

string testCalss::Info() { 
    return to_simple_string(this->beginningDate); 
} 

나는 형식을 변환해야 function이 문자열 유형이기 때문에 endDatestring으로 변 환하십시오.

In function boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::simple_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::ostream&)': 
/usr/include/boost/date_time/date_formatting.hpp:44: undefined reference to `boost::gregorian::greg_month::as_short_string() const' 
/usr/include/boost/date_time/date_formatting.hpp:49: undefined reference to `boost::gregorian::greg_month::as_long_string() const' 

내가 data_time는 헤더 전용 라이브러리뿐만 아니라 내가 구축하고 내 프로젝트에 추가해야 읽었습니다 : 프로그램이 연결되는 동안

나는 오류 메시지를 받고 있습니다.

이 명령을 gcc myapp.cpp -omyapp -lboost_date_time으로 시도했는데 cmake 프로젝트에서 g++을 사용하고 있기 때문에 작동하지 않으며 g ++에 대해 아무것도 찾지 못했습니다. 라이브러리를 연결하는 방법을 공식 부스트 문서에서

c++ -I path/to/boost_1_61_0 example.cpp -o example \ 
    ~/boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a 

그것의 예 :

나는이 시도했다. cmake 프로젝트에서 나는 cpp 파일이 거의 없습니다. 파일을 사용하여이 명령을 실행해야합니까?

이 오류를 해결하는 더 쉬운 방법이 있습니까?

답변

0

문제를 해결하는 방법을 찾았습니다. 내가 선택한 방식은 간단합니다. 우선 locate */boost/date_time* 명령을 사용하여 boostdate_time 라이브러리가 설치된 위치를 찾으십시오. 내가 사용중인 부스트 라이브러리의 버전을 알지 못했기 때문에 locate 명령을 다시 사용하여 boost/version.hpp 파일을 찾았습니다.

find_package(Boost 1.60.0 COMPONENTS date_time) 
if(Boost_FOUND) 
     include_directories(${Boost_INCLUDE_DIRS}) 
     target_link_libraries(Program ${Boost_DATE_TIME_LIBRARY}) 
endif() 

그게 전부 : 그 후 나는 내 CmakeLists.txt에 몇 줄을 추가했다.