I upgrade libtorch to 1.7.0 these days，and I find std::regex_replace not work with libtorch 1.7.0. I reproduce this issue through minimal code below:
1. I compile a shared library
main.cpp:
#include <regex>
#include <iostream>

void func()
{
    std::cout << std::regex_replace("{layer}", std::regex("layer"), "0") << std::endl;
};

then compile using g++:
g++ -fPIC -std=c++17 -shared main.cpp -o libmain.so


2. libtorch code
torch_test.cpp:
#include <torch/torch.h>
#include <iostream>

void func();

int main()
{
    func();
    setenv("CUDA_VISIBLE_DEVICES", "0,1", 1);
    auto device = torch::Device("cuda:0");
    std::cout << device << std::endl;
}



situation one

g++ -g -std=c++17 torch_test.cpp -o torch_test -I/opt/3rd/libtorch/include -I/opt/3rd/libtorch/include/torch/csrc/api/include -ltorch_cpu -ltorch_cuda -lc10 -lmain -L/opt/3rd/libtorch/lib -L./ -Wl,-rpath=/opt/3rd/libtorch/lib -Wl,-rpath=./

run torch_test, and the output is below:
$ ./torch_test 
{layer}
cuda:0

the std::regex_replace doesn’t work well

situation two

I change the libmain.so linking order
g++ -g -std=c++17 torch_test.cpp -o torch_test -I/opt/3rd/libtorch/include -I/opt/3rd/libtorch/include/torch/csrc/api/include -lmain -ltorch_cpu -ltorch_cuda -lc10 -L/opt/3rd/libtorch/lib -L./ -Wl,-rpath=/opt/3rd/libtorch/lib -Wl,-rpath=./

run torch_test, and the output is below:
$ ./torch_test 
{0}
[1]    2828402 segmentation fault (core dumped)  ./torch_test

the std::regex_replace works well, but libtorch code core dump.