Linux의 Boost 라이브러리 연결
-
05-07-2019 - |
문제
Boost의 ASIO를 사용하여 프로젝트를 구축하려고 노력하고 있으며 문제가 있습니다. 처음에는 모든 것이 헤더 파일에 있기 때문에 추가 라이브러리없이 프로젝트를 구축하려고했습니다.
내가 구축하려는 프로그램은 다음과 같습니다.
#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;
}
찾을 수 있습니다 여기 Boost의 웹 사이트에서.
그래서 처음에는 방금 가지고있었습니다.
-I /usr/include/boost_1_40_0
이로 인해 다음과 같은 오류가 발생했습니다.
make -k all
Building target: HelloWorld
Invoking: GCC C++ Linker
g++ -o"HelloWorld" ./main.o
./main.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost_1_40_0/boost/system/error_code.hpp:205: undefined reference to `boost::system::get_system_category()'
/usr/include/boost_1_40_0/boost/system/error_code.hpp:206: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost_1_40_0/boost/system/error_code.hpp:211: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost_1_40_0/boost/system/error_code.hpp:212: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost_1_40_0/boost/system/error_code.hpp:213: undefined reference to `boost::system::get_system_category()'
./main.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost_1_40_0/boost/asio/error.hpp:218: undefined reference to `boost::system::get_system_category()'
./main.o: In function `error_code':
/usr/include/boost_1_40_0/boost/system/error_code.hpp:312: undefined reference to `boost::system::get_system_category()'
./main.o: In function `posix_tss_ptr':
/usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create'
./main.o: In function `~posix_tss_ptr':
/usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete'
./main.o: In function `boost::asio::detail::posix_thread::join()':
/usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join'
./main.o: In function `~posix_thread':
/usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach'
collect2: ld returned 1 exit status
make: *** [HelloWorld] Error 1
make: Target `all' not remade because of errors.
시스템 라이브러리가 필요해 보였습니다. 그래서 나는 시작 가이드의 지시를 따랐다. 여기, 나에게 많은 도서관을 주었다. /usr/include/boost_1_40_0/stage/lib. 그들 가운데있었습니다 libboost_system.a. 따라서 나는 다음과 같이 컴파일하려고 시도했다.
-I /usr/include/boost_1_40_0
-L /usr/include/boost_1_40_0/stage/lib
-l libboost_system
그러나 나는 이것을 얻었다 :
make -k all
Building target: HelloWorld
Invoking: GCC C++ Linker
g++ -L/usr/lib -L/usr/include/boost_1_40_0/stage/lib -o"HelloWorld" ./main.o -llibboost_system
/usr/bin/ld: cannot find -llibboost_system
collect2: ld returned 1 exit status
make: *** [HelloWorld] Error 1
make: Target `all' not remade because of errors.
왜 그런지 잘 모르겠지만, 내가 시도하는 도서관이나 다른 사람을 식별 할 수없는 것 같습니다. 무엇을 잘못 할 수 있습니까? 미리 감사드립니다!
해결책
변화 -llibboost_system
에게 -lboost_system
.
Linux에서는 라이브러리 앞의 "Lib"접두사는 해당 라이브러리를 참조 할 때 사용되지 않습니다.
다른 팁
이 경우 제임스의 대답은 정확했지만, 다른 사람이 나처럼이 게시물을 우연히 발견하면 오래된 부스트 헤더를 최신 라이브러리와 연결하면이 메시지를받을 수 있다는 것을 알고 있습니다. get_system_category()
구체적으로 더 이상 사용되지 않았습니다. 실수로 배포판이있는 헤더를 포함하지만 내부 내부 부스트 사본과 연결하는 동안이 문제를 해결했습니다.
여전히 문제가 발생하면 링커 플래그에 추가하여 Posix-Shreads를 포함시킬 수 있습니다.
-lpthread