2010-11-22 4 views
1

내 부스트 간단한 코드 컴파일하려고 :이 명령부스트 컴파일 오류

g++ main.cpp -o main 

와 ++ g을 사용하여

#include <iostream> 
#include <boost/thread.hpp> 

void workerFunc(const char* msg, float delay_ms) 
{ 
boost::posix_time::milliseconds workTime(delay_ms); 

std::cout << "Worker: running, message = " << msg << std::endl; 

// Pretend to do something useful... 
boost::this_thread::sleep(workTime); 

std::cout << "Worker: finished" << std::endl; 
} 

int main(int argc, char* argv[]) 
{ 
std::cout << "main: startup" << std::endl; 

boost::thread workerThread(workerFunc, "Hello, Boost!", 2.5e3); 

std::cout << "main: waiting for thread" << std::endl; 

workerThread.join(); 

std::cout << "main: done" << std::endl; 

return 0; 
} 

을하지만이 같은 오류 얻을 :

main.cpp: In function `void workerFunc(const char*, float)': 
main.cpp:7: error: `boost::posix_time' has not been declared 
main.cpp:7: error: `milliseconds' was not declared in this scope 
main.cpp:7: error: expected `;' before "workTime" 
main.cpp:12: error: `boost::this_thread' has not been declared 
main.cpp:12: error: `workTime' was not declared in this scope 
main.cpp: In function `int main(int, char**)': 
main.cpp:21: error: no matching function for call to `boost::thread::thread(void (&)(const char*, float), const char[14], double)' 
/usr/include/boost/thread/thread.hpp:35: note: candidates are: boost::thread::thread(const boost::thread&) 
/usr/include/boost/thread/thread.hpp:38: note:     boost::thread::thread(const boost::function0<void, std::allocator<boost::function_base> >&) 
/usr/include/boost/thread/thread.hpp:37: note:     boost::thread::thread() 

을 무엇이 잘못되었으며 어떻게 컴파일해야합니까?

+0

libboost-date-time-dev가 설치되어 있습니까? – 0xAX

+0

확인 방법 ...? 내 바보 같은 질문에 대해 미안하지만, 리눅스에 익숙하지 않다. – flyjohny

답변

0

컴파일러는 일부 형식을 인식하지 못하기 때문에 일부 포함되지 않은 것을 의미합니다.

posix_time의 경우 코드 상단에 #include "boost/date_time/posix_time/posix_time.hpp"을 추가해야합니다.

7

http://www.boost.org/doc/libs/1_45_0/doc/html/date_time/posix_time.html

에 따르면이

#include "boost/date_time/posix_time/posix_time.hpp" 
+0

멋지지만, 이제는 "오류 :'boost :: this_thread '가 선언되지 않았다."... – flyjohny

+0

나는 사용중인 모든 것에 대한 헤더를 제공하는 문서. 검색하면 대답을 얻을 수 있습니다. –

+0

이 http://www.boost.org/doc/libs/1_45_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread에 따르면 #include 를 포함해야하지만 이 문제를 해결하지 않습니다 ... : ( – flyjohny

0

당신은 헤더 선언 posix_time을 포함해야합니다. 부스트 의사를보고 그것이 무엇인지 확인하십시오 (당신은 #include "boost/date_time/posix_time/posix_time_system.hpp"을 시도해 볼 수는 있지만 그 정도면 충분하지는 않습니다).

1

이전 버전의 Boost가 시스템에 설치되어있는 것으로 의심됩니다. 파일 /usr/include/boost/version.hpp을 읽으십시오. 사용중인 버전에 따라 버전 별 설명서 (Boost Documentation 참조)를 참조하십시오. 또는 시스템의 패키징 기능 (사용 가능한 경우)을 사용하거나 설치 지침 (Getting Started on Unix Variants 참조)에 따라 수동으로 Boost의 최신 버전을 설치하십시오.