CMake не может связать библиотеку Boost regex в Clion - PullRequest
0 голосов
/ 04 марта 2020

Я пытаюсь подготовить релиз Boost 1.72 для использования в моем проекте C ++. ОС - Windows 10. Я использую Clion в качестве IDE, а CMake 3.17 и g cc 8.1.0 в качестве набора инструментов. Я пытался следовать множеству различных инструкций в Интернете, пытаясь правильно «установить» Boost, и я закончил с этими шагами (все имена папок itali c являются допустимыми полными путями):

1) Распакуйте исходный код Boost, go в boost-sources-dir / tools / build, запустите bootstrap .bat g cc

2) Затем запустите b2 install --prefix = " said-boost-build-folder "

3) Затем добавьте обеспечить-boost-build-folder / bin в переменную PATH.

4) Go вернуться к boost-sources-dir и запустить b2 --build-dir = " boost-sources-dir \ build" --prefix = " boost-install-dir"toolset = g cc install --build-type = complete -j 4

5) Теперь у меня есть папки" include "и" lib "в увеличить установить-Dir . Я открываю Clion и добавляю параметры для CMake в настройках Clion:

-DBOOST_INCLUDEDIR="boost-install-dir\include" 
-DBOOST_LIBRARYDIR="boost-install-dir\lib" 
-DBOOST_ROOT="boost-install-dir"

И мой CMakeLists.txt ниже:

cmake_minimum_required(VERSION 3.14)
project(DBMSProject)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "--coverage")

find_package(Boost)
# I also tried to use the line below instead of a line above, but it gave me a strange error
# "Could NOT find Boost (missing: regex) (found version "1.72.0")"
# find_package(Boost REQUIRED COMPONENTS regex)

include_directories(${Boost_INCLUDE_DIRS})

add_executable(DBMSProject main.cpp /* some other stuff */)
target_link_libraries(DBMSProject -static)
#target_link_libraries(DBMSProject ${Boost_LIBRARIES})  # that didn't work
target_link_libraries(DBMSProject Boost::boost ${Boost_REGEX_LIBRARY})  # neither that does

Просто пример кода в main. cpp, чтобы увидеть если компиляция и компоновка работают:

/* Other headers */
#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;
    }
}

После попытки запустить эту программу, она выдает множество ошибок компоновки:

[100%] Linking CXX executable DBMSProject.exe
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::cpp_regex_traits_char_layer<char>::cpp_regex_traits_char_layer(boost::re_detail_107200::cpp_regex_traits_base<char> const&)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:370: undefined reference to `boost::re_detail_107200::cpp_regex_traits_char_layer<char>::init()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::raw_storage::extend(unsigned long long)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/regex_raw_buffer.hpp:131: undefined reference to `boost::re_detail_107200::raw_storage::resize(unsigned long long)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::save_state_init::save_state_init(boost::re_detail_107200::saved_state**, boost::re_detail_107200::saved_state**)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/perl_matcher_non_recursive.hpp:110: undefined reference to `boost::re_detail_107200::get_mem_block()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::save_state_init::~save_state_init()':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/perl_matcher_non_recursive.hpp:118: undefined reference to `boost::re_detail_107200::put_mem_block(void*)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp()':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/perl_matcher_common.hpp:221: undefined reference to `boost::re_detail_107200::verify_options(unsigned int, boost::regex_constants::_match_flags)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::unwind_extra_block(bool)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/perl_matcher_non_recursive.hpp:1371: undefined reference to `boost::re_detail_107200::put_mem_block(void*)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `void boost::re_detail_107200::raise_error<boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >(boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::error_type)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/pattern_except.hpp:75: undefined reference to `boost::re_detail_107200::raise_runtime_error(std::runtime_error const&)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::extend_stack()':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/perl_matcher_non_recursive.hpp:236: undefined reference to `boost::re_detail_107200::get_mem_block()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, long long)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_parser.hpp:241: 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, long long)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_parser.hpp:242: undefined reference to `boost::regex_error::raise() const'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_parser.hpp:241: undefined reference to `boost::regex_error::~regex_error()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_parser.hpp:241: undefined reference to `boost::regex_error::~regex_error()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail_107200::re_syntax_base*)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:785: 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, long long)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:786: undefined reference to `boost::regex_error::raise() const'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:785: undefined reference to `boost::regex_error::~regex_error()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:874: 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, long long)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:875: undefined reference to `boost::regex_error::raise() const'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:874: undefined reference to `boost::regex_error::~regex_error()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:785: undefined reference to `boost::regex_error::~regex_error()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:874: undefined reference to `boost::regex_error::~regex_error()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail_107200::re_syntax_base*)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:940: 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, long long)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:941: undefined reference to `boost::regex_error::raise() const'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:940: undefined reference to `boost::regex_error::~regex_error()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:940: undefined reference to `boost::regex_error::~regex_error()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmap(boost::re_detail_107200::re_syntax_base*, unsigned char*, unsigned int*, unsigned char)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:1141: 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, long long)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:1142: undefined reference to `boost::regex_error::raise() const'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:1141: undefined reference to `boost::regex_error::~regex_error()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:1141: undefined reference to `boost::regex_error::~regex_error()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::cpp_regex_traits_implementation<char>::error_string[abi:cxx11](boost::regex_constants::error_type) const':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:447: undefined reference to `boost::re_detail_107200::get_default_error_string(boost::regex_constants::error_type)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:449: undefined reference to `boost::re_detail_107200::get_default_error_string(boost::regex_constants::error_type)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::insert_state(long long, boost::re_detail_107200::syntax_element_type, unsigned long long)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/basic_regex_creator.hpp:322: undefined reference to `boost::re_detail_107200::raw_storage::insert(unsigned long long, unsigned long long)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::object_cache<boost::re_detail_107200::cpp_regex_traits_base<char>, boost::re_detail_107200::cpp_regex_traits_implementation<char> >::get(boost::re_detail_107200::cpp_regex_traits_base<char> const&, unsigned long long)':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::cpp_regex_traits_implementation<char>::lookup_collatename[abi:cxx11](char const*, char const*) const':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:680: undefined reference to `boost::re_detail_107200::lookup_default_collate_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::re_detail_107200::cpp_regex_traits_implementation<char>::init()':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:721: undefined reference to `boost::re_detail_107200::raise_runtime_error(std::runtime_error const&)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:736: undefined reference to `boost::re_detail_107200::get_default_error_string(boost::regex_constants::error_type)'
CMakeFiles\DBMSProject.dir/objects.a(main.cpp.obj): In function `boost::cpp_regex_traits<char>::get_catalog_name[abi:cxx11]()':
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:1117: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:1117: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:/Users/dsomov/Documents/Programs/boost/include/boost-1_72/boost/regex/v4/cpp_regex_traits.hpp:1117: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\DBMSProject.dir\build.make:119: DBMSProject.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:92: CMakeFiles/DBMSProject.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:99: CMakeFiles/DBMSProject.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:134: DBMSProject] Error 2

Но я могу ясно увидеть определения " отсутствующие "символы в том же файле .hpp, где и ошибки! Что я делаю не так?

1 Ответ

0 голосов
/ 06 марта 2020

Я наконец получил его на работу. Мой CMakeLists.txt теперь выглядит следующим образом:

cmake_minimum_required(VERSION 3.14)
project(DBMSProject)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "--coverage")
set(CMAKE_PREFIX_PATH ${BOOST_LIBRARYDIR}\\cmake)

find_package(Boost CONFIG REQUIRED COMPONENTS regex)
include_directories(${Boost_INCLUDE_DIRS})

add_executable(DBMSProject main.cpp /* stuff */)
target_link_libraries(DBMSProject -static)
#target_link_libraries(DBMSProject ${Boost_LIBRARIES}) # haven't tried that but I think it might work as well
target_link_libraries(DBMSProject Boost::regex)

Также оказалось, что мне не нужны параметры -DBOOST ... для CMake, если я не использую их в CMakeLists.txt, поэтому я исключил из них -DBOOST_INCLUDEDIR и -DBOOST_ ROOT.

...