I have a Ubuntu 20.04.2 LTS
machine and have gcc 9.4.0
by default.
I built a GCC-12.1.0
from source and wrote a very simple cpp program and compiled it with /path_to_gcc12_bin/g++
.
Then I run gdb
to follow, by pressing s
, and it shows the program includes the newer version c++
header files of gcc12
.
The shared library libstdc++.so.6
is still linked to the system path one.
My question is :
How does/path_to_gcc12_bin/g++
knows to use the newer version(its own) header files?
I don't have CPLUS_INCLUDE_PATH
env variables or anything similar set up.
If I build the program using the system g++
, it would use system path include files, that is /usr/include/c++/9/bits/regex.h
.
P.S. move /path_to_gcc12
the whole directory to somewhere else, g++
can still include the newer header files correctly.
test.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 9Breakpoint 1 at 0x4036f7: file test.cpp, line 9.(gdb) rStarting program: /home/tian/GCC-12.1.0/bin/test Breakpoint 1, main () at test.cpp:99 cout << std::regex_search("GetValue", m, re) << endl; // returns true, and m[0] contains "Get"(gdb) sstd::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:24092409 { 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