Code Blocks 配置 MinGW Distro 使用boost库

mingw的编译发行版常见的有两个: MinGW Distro 和 TDM-GCC.  MinGW Distro中更是包含了boost库,不用我们再编译,而且都是最新的库,非常方便。可以去这里下载点击打开链接,

下载最新版 mingw-13.0.exe,将Code Blocks 的安装目录下的MinGW下的文件全部删除,之后将下载的文件双击, 提取到MinGW文件夹下。

之后启动Code Blocks,会提示检测不到编译器。

将编译器所在的目录收到改为新的MinGW \ bin 下,另外将当前的对应工具从mingw32版本改为目录下对应的版本。

boost库大部分直接包含头文件.hpp文件即可以使用,少部分需要编译,比如正则表达式:

Code Blocks库下的boost的正则表达式的使用方法如下:

1、在设置--编译器设置里,添加boost库的所有头文件到搜索路径:

2、在连接器中,添加正则表达式对应的链接库文件:


添加测试代码:

    #include <stdio.h>
    #include <string>
    #include <iterator>
    #include <boost/regex.hpp>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    {
        std::string str("infoasdf123unil98oasdfa686^&*(432");
        boost::regex e1("[0-9]+");



        std::string::const_iterator start, end;
        start = str.begin();
        end = str.end();

        boost::match_results<std::string::const_iterator> what;
        boost::match_flag_type flags = boost::match_default;

        while (regex_search(start, end, what, e1, flags))
        {
            cout << "finded number: " << string(what[0].first, what[0].second) << endl;
            start = what[0].second;
        }
        return 0;
    }

正常运行,得到结果:


nuwen.net 是微软员工个人编译的Mingw 版本,使用的线程模型是win32 (gcc -v可查看),所以有些C++11的特性无法使用。

以下部分摘自:点击打开链接

GCC Threading model (posix vs win32)

Mingw-Builds (and the experimental rubenvb packages) also let you choose between the threading model internally used by (lib)gcc:

  • posix (built upon MinGW-w64's winpthreads)
    • "an implementation of POSIX threads for win32 is also available under the experimental directory. Its main goal is to support C+11 standard threading, which supports only using POSIX threads at the moment."http://mingw-w64.sourceforge.net/
    • enables C11 library features contained in the headers <thread>, <mutex>, and <future>.
    • Performance degradation in specific scenarios. C11 functionality is significantly slower than native Win32 implementation or even MSVS2012's implementation.
  • win32
    • uses native Win32 threading functions.
    • no C11 <thread>, <mutex>, or <future>
    • best performance

More reading: http://sourceforge.net/mailarchive/message.php?msg_id=28014658


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值