gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex

Posted 花狗Fdog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex相关的知识,希望对你有一定的参考价值。

出现这个错误的原因应该是gcc版本的问题。

查看版本命令:
gcc --version

不出意外的话应该是4.8.x的版本

经查询gcc4.9才支持c++的正则表达式,所以我们需要将gcc进行升级。

先找一个gcc4.9的源码包进行安装(自己找一个)

mkdir build
…/./configure
make & make install

执行configure可能报错:
linux : error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.

说明需要安装这三个库:
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz

tar.bz2 解压命令 tar -jxvf
tar.gz 解压命令 tar -zxvf

./configure
make & make install

执行gmp的configure可能报错:
error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons)

说明缺少m4这个库
wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.bz2

执行./configure可能报错:
./stdio.h:477:1: error: ‘gets’ undeclared here (not in a function)
_GL_WARN_ON_USE (gets, “gets is a security hole - use fgets instead”);

进入m4/lib 找到一个stdio.in.h的问题,找不到可以试试使用find -name stdio.in.h

把第一行注释掉

_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

添加下面

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

然后一路编译这几个库

到了编译gcc的时候

configure又报错了

I suspect your system does not have 32-bit developement libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

执行
sudo yum install glibc-devel.i686
sudo yum install libgcc.i686

哦终于过了
执行make
make install走起

哦忘了说了,如果你的机子是多核的可以执行并行编译 make -j8 后面的数字代表核数

这段时间可以看一部电影,不出意外看完了make还没执行完。。。。。

我感觉劝退萌新的不是语言本身,倒是linux下的环境配置。

以上是关于gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex的主要内容,如果未能解决你的问题,请参考以下文章

gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex

gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex

C++11多线程运行报错:terminate called without an active exception(没有join或detach子线程)

C++11多线程运行报错:terminate called without an active exception(没有join或detach子线程)

学习笔记50--terminate called after throwing an instance of ‘YAML::BadFile‘ what(): bad file报错踩坑

C++运行报错:terminate called after throwing an instance of ‘std::future_error‘(promise对象调用set前不能销毁!)