1 Востаннє редагувалося ACTIONFENIX (31.01.2018 16:34:59)

Тема: Не лінкується boost::regex

Встановив boost під GCC. Початкові файли з архіву boost знаходяться в C:\boost_1_66_0, а самі скомпільовані бібліотеки в C:\boost
Намагаюсь зібрати наступний код:

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

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
    
    return 0;
}

Збираю з наступними опціями: g++ test.cpp -o test2 -std=c++17 -Wall -Wextra -LC:\boost\lib\libboost_regex-mgw63-mt-x32-1_66.dll.a -I C:\boost_1_66_0
Але отримую цілий ряд помилок:

Прихований текст
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660027cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[__ZN5boost16re_detail_10660027cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE]+0x23): undefined reference to `boost::re_detail_106600::cpp_regex_traits_char_layer<char>::init()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660011raw_storage6extendEj[__ZN5boost16re_detail_10660011raw_storage6extendEj]+0x41): undefined reference to `boost::re_detail_106600::raw_storage::resize(unsigned int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[__ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0x217): undefined reference to `boost::regex_error::regex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants::error_type, int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[__ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0x224): undefined reference to `boost::regex_error::raise() const'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[__ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0x22e): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[__ZN5boost16re_detail_10660018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0x284): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x113): undefined reference to `boost::regex_error::regex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants::error_type, int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x120): undefined reference to `boost::regex_error::raise() const'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x12a): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x2e6): undefined reference to `boost::regex_error::regex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants::error_type, int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x2f3): undefined reference to `boost::regex_error::raise() const'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x2fd): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x33d): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE]+0x377): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE]+0x159): undefined reference to `boost::regex_error::regex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants::error_type, int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE]+0x166): undefined reference to `boost::regex_error::raise() const'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE]+0x170): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE]+0x30c): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh]+0x28f): undefined reference to `boost::regex_error::regex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants::error_type, int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh]+0x29c): undefined reference to `boost::regex_error::raise() const'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh]+0x2a6): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh]+0xa0c): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZNK5boost16re_detail_10660031cpp_regex_traits_implementationIcE12error_stringB5cxx11ENS_15regex_constants10error_typeE[__ZNK5boost16re_detail_10660031cpp_regex_traits_implementationIcE12error_stringB5cxx11ENS_15regex_constants10error_typeE]+0x8b): undefined reference to `boost::re_detail_106600::get_default_error_string(boost::regex_constants::error_type)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZNK5boost16re_detail_10660031cpp_regex_traits_implementationIcE12error_stringB5cxx11ENS_15regex_constants10error_typeE[__ZNK5boost16re_detail_10660031cpp_regex_traits_implementationIcE12error_stringB5cxx11ENS_15regex_constants10error_typeE]+0xe8): undefined reference to `boost::re_detail_106600::get_default_error_string(boost::regex_constants::error_type)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12insert_stateEiNS0_19syntax_element_typeEj[__ZN5boost16re_detail_10660019basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12insert_stateEiNS0_19syntax_element_typeEj]+0x95): undefined reference to `boost::re_detail_106600::raw_storage::insert(unsigned int, unsigned int)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost12object_cacheINS_16re_detail_10660021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j[__ZN5boost12object_cacheINS_16re_detail_10660021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j]+0x1c): undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost12object_cacheINS_16re_detail_10660021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j[__ZN5boost12object_cacheINS_16re_detail_10660021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j]+0x76): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost12object_cacheINS_16re_detail_10660021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j[__ZN5boost12object_cacheINS_16re_detail_10660021cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j]+0x92): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZNK5boost16re_detail_10660031cpp_regex_traits_implementationIcE18lookup_collatenameB5cxx11EPKcS4_[__ZNK5boost16re_detail_10660031cpp_regex_traits_implementationIcE18lookup_collatenameB5cxx11EPKcS4_]+0x112): undefined reference to `boost::re_detail_106600::lookup_default_collate_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660031cpp_regex_traits_implementationIcE4initEv[__ZN5boost16re_detail_10660031cpp_regex_traits_implementationIcE4initEv]+0xed): undefined reference to `boost::re_detail_106600::raise_runtime_error(std::runtime_error const&)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16re_detail_10660031cpp_regex_traits_implementationIcE4initEv[__ZN5boost16re_detail_10660031cpp_regex_traits_implementationIcE4initEv]+0x129): undefined reference to `boost::re_detail_106600::get_default_error_string(boost::regex_constants::error_type)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameB5cxx11Ev[__ZN5boost16cpp_regex_traitsIcE16get_catalog_nameB5cxx11Ev]+0x1f): undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameB5cxx11Ev[__ZN5boost16cpp_regex_traitsIcE16get_catalog_nameB5cxx11Ev]+0x40): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:\Users\ACTION~1\AppData\Local\Temp\cc4mFQ06.o:test.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameB5cxx11Ev[__ZN5boost16cpp_regex_traitsIcE16get_catalog_nameB5cxx11Ev]+0x4e): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2.exe: error: ld returned 1 exit status

То як вирішити цю проблему?

UPD: проблема вирішилася перекомпіляцією бібліотеки regex через

b2 --prefix=C:\boost --with-regex --toolset=gcc --link=shared address-model=32 install

і компіляцією самої програми через

g++ test.cpp -o test2 -std=c++17 -Wall -Wextra -I C:\boost\include\boost-1_66 -LC:\boost\lib -lboost_regex-mgw63-mt-x32-1_66 -static

Я так думаю, що проблема була в тому, що під час компіляції всієї бібліотеки boost першого разу в консолі видавало якісь попередження про платформу x64 і тому під час другої спроби я вказав ключ address-model=32

Подякували: LoganRoss, iovchynnikov2