我有一个
Ubuntu 20.04.2 LTS
机器和
gcc 9.4.0
默认情况下。
我建造了一个
GCC-12.1.0
并编写了一个非常简单的cpp程序,并使用
/path_to_gcc12_bin/g++
。
然后我就跑
gdb
按
s
,并显示该程序包含更新版本
c++
的头文件
gcc12
。
共享库
libstdc++.so.6
仍然链接到系统路径一。
我的问题是:
如何
/路径_to_gcc12_bin/g++
知道使用新版本(自己的)头文件吗?
我没有
CPLUS_INCLUDE_PATH
env变量或任何类似设置。
如果我使用系统构建程序
g++
,它将使用系统路径include文件,即
/usr/include/c++/9/bits/regex.h
。
P.S。
移动
/path_to_gcc12
整个目录到其他地方,
g++
仍然可以正确地包括较新的头文件。
测试.cpp
#include <iostream>
#include <regex>
using namespace std;
int main(){
std::regex re("Get|GetValue");
std::cmatch m;
cout << std::regex_search("GetValue", m, re) << endl; // returns true, and m[0] contains "Get"
cout << std::regex_match ("GetValue", m, re) << endl; // returns true, and m[0] contains "GetValue"
cout << std::regex_search("GetValues", m, re) << endl; // returns true, and m[0] contains "Get"
cout << std::regex_match ("GetValues", m, re) << endl; // returns false
}
tian@tian-B250M-Wind:~/GCC-12.1.0/bin$ LD_PRELOAD='/home/tian/GCC-12.1.0/lib64/libstdc++.so.6.0.30' gdb ./test
(gdb) b 9
Breakpoint 1 at 0x4036f7: file test.cpp, line 9.
(gdb) r
Starting program: /home/tian/GCC-12.1.0/bin/test
Breakpoint 1, main () at test.cpp:9
9 cout << std::regex_search("GetValue", m, re) << endl; // returns true, and m[0] contains "Get"
(gdb) s
std::regex_search<char, std::allocator<std::__cxx11::sub_match<char const*> >, std::__cxx11::regex_traits<char> > (__s=0x42c0f6 "GetValue", __m=..., __e=..., __f=std::regex_constants::_S_default)
at /home/tian/GCC-12.1.0/include/c++/12.1.0/bits/regex.h:2409
2409 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
at /home/tian/GCC-12.1.0/include/c++/12.1.0/bits/regex.h:2409