使用qtcreator构建boostc++1.48.0

build boost c++ 1.48.0 with qt creator

本文关键字:boostc++1 构建 qtcreator 使用      更新时间:2023-10-16

我一直在尝试构建c++boost来与qt创建者一起工作,但到目前为止,我得到的只是对不同事物的未定义引用,所以以下是我迄今为止所做的:-

  1. 我通过运行bootstrap.bat然后运行bjam来构建c++boost
  2. 我在qtcreator.pro项目中包含了该路径

像这个

QT += core gui
TARGET = Heap
TEMPLATE = app
INCLUDEPATH += C:boostboost_1_48_0
LIBS += -L"C:/boost/boost_1_48_0/stage/lib"
SOURCES += 
    main.cpp
HEADERS  += 
    clss.h 
    inputstream.h 
    outputstream.h 
    myexception.h 
    heaptest.h 
    comparable.h 
    heap.h
FORMS    +=

这是我在上测试的样本代码

#include <boost/regex.hpp>
#include <iostream>
#include <string>
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;
    }
}

这是我得到的编译错误

debug/main.o: In function `cpp_regex_traits_char_layer':
C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:366: undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/regex_raw_buffer.hpp:131: undefined reference to `boost::re_detail::raw_storage::resize(unsigned int)'
debug/main.o: In function `save_state_init':
C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/perl_matcher_non_recursive.hpp:107: undefined reference to `boost::re_detail::get_mem_block()'
debug/main.o: In function `~save_state_init':
C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/perl_matcher_non_recursive.hpp:115: undefined reference to `boost::re_detail::put_mem_block(void*)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/perl_matcher_common.hpp:206: undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/perl_matcher_non_recursive.hpp:1117: undefined reference to `boost::re_detail::put_mem_block(void*)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/pattern_except.hpp:75: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_parser.hpp:218: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::raise() const'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:798: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:799: undefined reference to `boost::regex_error::raise() const'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:799: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:799: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:880: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:881: undefined reference to `boost::regex_error::raise() const'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:881: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:881: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:945: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:946: undefined reference to `boost::regex_error::raise() const'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:946: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:946: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:1148: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:1149: undefined reference to `boost::regex_error::raise() const'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:1149: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:1149: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/perl_matcher_non_recursive.hpp:213: undefined reference to `boost::re_detail::get_mem_block()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:442: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:444: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/basic_regex_creator.hpp:321: undefined reference to `boost::re_detail::raw_storage::insert(unsigned int, unsigned int)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/pending/object_cache.hpp:75: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/pending/object_cache.hpp:75: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:633: undefined reference to `boost::re_detail::lookup_default_collate_name(std::string const&)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:675: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:690: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:1059: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:1062: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
debug/main.o:C:UsersAamerDesktopHeap-build-desktop-Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/regex/v4/cpp_regex_traits.hpp:1062: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug/Heap.exe] Error 1
mingw32-make.exe: *** [debug] Error 2
16:05:31: The process "C:Qtqtcreator-2.4.0mingwbinmingw32-make.exe" exited with code 2.
Error while building project Heap (target: Desktop)
When executing build step 'Make'

我该如何构建?

尝试将LIBS += -L"C:/boost/boost_1_48_0/stage/lib"行更改为:

LIBS += -L"C:/boost/boost_1_48_0/stage/lib" -lboost_regex

(将boost_regex替换为已构建库的实际名称(可能类似于boost_regex-mgw44-mt-1_48))