Неопределенная ссылка, когда Gcc компилирует Boost ::Существует регулярное выражение с несколькими версиями boost

Я пытался установить Boost на Linux-машину (CentOs, версия Linux 2.6.9 -67.ELsmp ). Я следовал инструкциям на веб-странице Boost Начало работы . Скачал и извлек файлы, затем добавил префикс, потому что я не пользователь root.

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

Я захожу в /my _path/boost -1.49.0 и проверяю, есть ли там файлы /include/boost/ и /lib/.

также я установил LD _LIBRARY _PATH в /my _path/boost -1.49.0/lib/.

Чтобы проверить, успешно ли я установил, я компилирую следующий код:

main.cpp

#include 
#include 
#include 

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, std::allocator >::basic_regex(char const*, 
unsigned int, std::allocator const&)':: 
undefined reference to `boost::reg_expression, 
std::allocator >::reg_expression(char const*, unsigned int, 
std::allocator const&)'

/tmp/ccpu82sB.o(.gnu.linkonce.t.
_ZN5boost11basic_regexIcNS_12regex_traitsIcEESaIcEED1Ev+0x11): In function 
`boost::basic_regex, 
std::allocator>::~basic_regex()':
: undefined reference to `boost::reg_expression, 
std::allocator >::~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, std::allocator > >, 
std::allocator, std::allocator > > > >, 
boost::regex_traits, std::allocator>
::perl_matcher(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, 
boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, 
std::allocator, std::allocator > > > > >&, 
boost::reg_expression, std::allocator > 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)

По какой-то причине меня просят не обновлять boost в /usr/include/boost. Есть ли что-нибудь, что может помочь мне решить эту проблему, установить boost в локальную папку и просто изменить путь, как включить и связать, чтобы использовать разные версии?

Я не уверен, глупый это вопрос или нет, но я искал в Google, но в основном связанные вопросы неправильно заданы -I, -L и -l в команде gcc. я понятия не имею о сообщение об ошибке выше, действительно сводит меня с ума. Любая помощь приветствуется.

Спасибо за терпение и время.

7
задан Job 24 April 2012 в 08:43
поделиться