2012-04-23 1 views
6

Linux 컴퓨터 (CentOS, Linux 버전 2.6.9-67.ELsmp)에 부스트를 설치하려고했습니다. 부스트 Getting Started 웹 페이지의 지침을 따랐습니다. 파일을 다운로드하고 압축을 푼 다음 루트 사용자가 아니기 때문에 접두사를 추가합니다.Gcc가 여러 버전의 부스트가있는 Boost :: regex를 컴파일 할 때 정의되지 않은 참조가 있습니다.

./bootstrap.sh --prefix=/my_path/boost-1.49.0 
./b2 install 

나는 /my_path/boost-1.49.0로 이동하고있다 확인// 부스트를 포함 /와// lib에이 파일이 포함되어 있습니다.

또한 LD_LIBRARY_PATH를 /my_path/boost-1.49.0/lib/로 설정했습니다. 내가 성공적으로 설치 한 경우

테스트하기 위해, 나는 다음과 같은 코드를 컴파일

MAIN.CPP

#include <boost/regex.hpp> 
#include <iostream> 
#include <string> 

using namespace boost; 
using namespace std; 

int main(int argc, char *argv[]) 
{ 
    string line = "12345"; 
    regex pattern("^123"); 
    if (regex_match(line, pattern)) cout << "match." << endl; 
    else cout << "not match." << endl; 
    return 1; 
} 

를 그리고 명령에 의해 컴파일 :

g++ -v -I /my_path/boost-1.49.0/include/boost -L /my_path/boost-1.49.0/lib main.cpp -lboost_regex -o example 

및 생성 다음과 같은 오류 :

Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs 
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux 
Thread model: posix 
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9) 
/usr/libexec/gcc/x86_64-redhat-linux/3.4.6/cc1plus -quiet -v -I /my_path/boost-1.49.0/include/boost/ -D_GNU_SOURCE main.cpp -quiet -dumpbase main.cpp -mtune=k8 -auxbase main -version -o /tmp/ccW0ON8y.s 
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../x86_64-redhat-linux/include" 
#include "..." search starts here: 
#include <...> search starts here: 
/my_path/boost-1.49.0/include/boost/ 
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6 
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/x86_64-redhat-linux 
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward 
/usr/local/include 
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/include 
/usr/include 
End of search list. 
GNU C++ version 3.4.6 20060404 (Red Hat 3.4.6-9) (x86_64-redhat-linux) 
     compiled by GNU C version 3.4.6 20060404 (Red Hat 3.4.6-9). 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
as -V -Qy -o /tmp/ccpu82sB.o /tmp/ccW0ON8y.s 
GNU assembler version 2.15.92.0.2 (x86_64-redhat-linux) using BFD version 2.15.92.0.2 20040927 
/usr/libexec/gcc/x86_64-redhat-linux/3.4.6/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o example /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/3.4.6/crtbegin.o -L /my_path/boost-1.49.0/lib/ -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../.. -L/lib/../lib64 -L/usr/lib/../lib64 /tmp/ccpu82sB.o -lboost_regex -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/3.4.6/crtend.o /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/crtn.o 
/tmp/ccpu82sB.o(.gnu.linkonce.t._ZN5boost11basic_regexIcNS_12regex_ 
traitsIcEESaIcEEC1EPKcjRKS3_+0x27): In function `boost::basic_regex<char, 
boost::regex_traits<char>, std::allocator<char> >::basic_regex(char const*, 
unsigned int, std::allocator<char> const&)':: 
undefined reference to `boost::reg_expression<char, boost::regex_traits<char>, 
std::allocator<char> >::reg_expression(char const*, unsigned int, 
std::allocator<char> const&)' 

/tmp/ccpu82sB.o(.gnu.linkonce.t. 
_ZN5boost11basic_regexIcNS_12regex_traitsIcEESaIcEED1Ev+0x11): In function 
`boost::basic_regex<char, boost::regex_traits<char>, 
std::allocator<char>>::~basic_regex()': 
: undefined reference to `boost::reg_expression<char, boost::regex_traits<char>, 
std::allocator<char> >::~reg_expression()' 
/tmp/ccpu82sB.o(.gnu.linkonce.t. 
_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub 
_matchIS6_EEENS_12regex_traitsIcEESaIcEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_ 
14reg_expressionIcSB_SC_EENS_15regex_constants12_match_flagsE+0xa1): In function 
`boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, 
std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, 
std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, 
std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, 
boost::regex_traits<char>, std::allocator<char>> 
::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char 
const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, 
boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > >, 
std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, 
std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, 
boost::reg_expression<char, boost::regex_traits<char>, std::allocator<char> > const&, 
boost::regex_constants::_match_flags)': 

그러나 만약 내가 방금 설치 한 시스템을 관리하는 기본 부스트로 컴파일하면

g++ -v main.cpp -lboost_regex -o example 

그럼 괜찮습니다.

LDD 예 내가 인해 몇 가지 이유에

libboost_regex.so.1 => /usr/lib64/libboost_regex.so.1 (0x0000002a95557000) 

있어 내가는/usr/포함/부스트의 향상을 업데이트하지 말라고 오전. 로컬 폴더에 설치를 향상시키고 다른 버전을 포함하고 링크하는 방법을 변경하는이 문제로 해결할 수있는 방법이 있습니까?

이 질문이 벙어리인지 아닌지는 잘 모르겠지만 구글로 검색했지만 대부분 관련 질문이 gcc 명령에서 -I, -L 및 -l로 올바르게 설정되지 않았습니다. 위의 오류 메시지가 에 대해 알지 못합니다. 정말 미치게합니다. 어떤 도움을 주셔서 감사합니다.

양해 해 주셔서 감사합니다.

+0

링커는 명확하게 설치된 부스트 라이브러리를 포함하지 않습니다

당신과 함께 시도 할 수 있습니다. '-L <당신의 lib 경로>'를'-L <당신의 lib 경로>'로 변경하려고합니까? – HonkyTonk

+0

아니요. 실제로 컴파일 명령에는 -L과 경로 사이에 공백이 없습니다. 게시물의 오타입니다. 죄송합니다. – user1350816

답변

8

아마도 컴파일 명령에서 /my_path/boost-1.49.0/include/boost을 포함 경로로 사용한 다음 소스 코드에 #include <boost/regex.hpp>을 사용했기 때문일 수 있습니다.

내 생각 엔 regex.hpp이 (가) /my_path/boost-1.49.0/include/boost/boost/regex.hpp에서 검색되었습니다. 그것은 분명히 발견되지 않으므로 시스템 1이 발견됩니다. g++ -v -I /my_path/boost-1.49.0/include -L /my_path/boost-1.49.0/lib main.cpp -lboost_regex -o example

+0

오, 고마워요 !! 이것은 정확하게 문제의 원인이며, 그 미묘한 부분을 알지 못했습니다. – user1350816

관련 문제