나는 스레드를 향상시키는 것이 처음이고 내가 찾은 간단한 예제를 컴파일하려고합니다.
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
void workerFunc()
{
boost::posix_time::seconds workTime(3);
std::cout << "Worker: running" << 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);
std::cout << "main: waiting for thread" << std::endl;
workerThread.join();
std::cout << "main: done" << std::endl;
return 0;
}
나는 그것을 컴파일하고 있으며 다음 g++ -Wall -I $(BOOST)/include -L $(BOOST)/lib/ -lboost_system test.cpp
과 같은 오류가 발생합니다.
/tmp/ccp180QW.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x160): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x16c): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x178): undefined reference to `boost::system::system_category()'
/tmp/ccp180QW.o: In function `boost::thread_exception::thread_exception(int, char const*)':
test.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x14): undefined reference to `boost::system::system_category()'
/tmp/ccp180QW.o: In function `boost::detail::thread_data_base::thread_data_base()':
test.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]+0x24): undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/ccp180QW.o: In function `boost::this_thread::sleep(boost::posix_time::ptime const&)':
test.cpp:(.text._ZN5boost11this_thread5sleepERKNS_10posix_time5ptimeE[boost::this_thread::sleep(boost::posix_time::ptime const&)]+0x3e): undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
/tmp/ccp180QW.o: In function `boost::thread::start_thread()':
test.cpp:(.text._ZN5boost6thread12start_threadEv[boost::thread::start_thread()]+0x15): undefined reference to `boost::thread::start_thread_noexcept()'
/tmp/ccp180QW.o: In function `boost::thread::~thread()':
test.cpp:(.text._ZN5boost6threadD2Ev[_ZN5boost6threadD5Ev]+0x15): undefined reference to `boost::thread::detach()'
/tmp/ccp180QW.o: In function `boost::thread::get_id() const':
test.cpp:(.text._ZNK5boost6thread6get_idEv[boost::thread::get_id() const]+0x18): undefined reference to `boost::thread::native_handle()'
/tmp/ccp180QW.o: In function `boost::thread::join()':
test.cpp:(.text._ZN5boost6thread4joinEv[boost::thread::join()]+0x6d): undefined reference to `boost::thread::join_noexcept()'
/tmp/ccp180QW.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
test.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED2Ev[_ZN5boost6detail11thread_dataIPFvvEED5Ev]+0x1f): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccp180QW.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data<void (*)()>]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: ld returned 1 exit status
Ubuntu 11.10에서 부스트 1.55 버전과 gcc 4.6.1을 사용하고 있습니다. 내가 무엇을 놓치고 있습니까?
감사
마지막에 라이브러리 이름을 넣으려면 순서를 변경해보십시오.
나는 이것을 시도했다 (부스트는 이미 기본 포함 및 링커 경로에 있으므로 포함 및 링커 위치를 지정할 필요가 없으며 일부 라이브러리 이름 만) 나를 위해 일했습니다.
g++ -Wall test.cpp -o test -lboost_system -lboost_thread
따라서 예를 들어 다음을 원할 수 있습니다.
g++ -Wall -I$(BOOST)/include test.cpp -o test -L$(BOOST)/lib -lboost_system -lboost_thread
당신이 원래 보여준 방식대로하면, 나는 당신이했던 것과 같은 오류가 발생했습니다.
또한 다음과 같이 컴파일 및 링크 단계를 분할하여 모든 것을 더 명확하게 만들 수 있습니다 (소스 파일이 두 개 이상있는 즉시이 작업을 수행하고 싶을 것입니다).
g++ -c -Wall -o test.o test.cpp
g++ test.o -o test -lboost_system -lboost_thread
첫 번째 줄의 -c는 g ++에게 링크가 아닌 객체를 컴파일하도록 지시합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다