I have pack libtorch libraries(1.2) to a computational module in a so file with cmake, if I only test this module , everythin is ok. However, if I link this so file to another module and generate a exe file, when I run the exe file, function torch::jit::load(model_path) crashed:
terminate called after throwing an instance of ‘std::regex_error’, what():  regex_error.
When I re-link libtorch.so to the excutable file in the CmakeLists.txt, and recompile the exe file, the problem solved. I’m puzzled that I have link the libtorch.so in the previous computational module, and excutable file link it with noproblem, why the torch::jit::load crashed if I don’t llink libtorch.so a second time?
This is exe comiple infomation, with no link libtorch.so
Building depend module “extern/private/scenarios/webpage/qa/src/query_modify:webpage”
[100%] Built target webpage
– The C compiler identification is GNU 4.9.2
– The CXX compiler identification is GNU 4.9.2
– Check for working C compiler: /usr/local/bin/gcc
– Check for working C compiler: /usr/local/bin/gcc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /usr/local/bin/g++
– Check for working CXX compiler: /usr/local/bin/g++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Get dep module c/qa:Aoeiuv_c_qa
– Get dep module c/proto:Aoeiuv_c_proto
– Get dep module c/common/base:Aoeiuv_c_common_base
– Get dep module c/extern/misc_proto:Aoeiuv_c_extern_misc_proto
– Get dep module extern/private/scenarios/webpage/common/server_common:qc_server_common
– Get dep module extern/private/scenarios/webpage/qa/src/query_modify:webpage
– Configuring done
– Generating done
– Build files have been written to: /data/qc_rebuild_webpage/Aoeiuv/extern/private/scenarios/webpa
Scanning dependencies of target test_webpage
[ 50%] Building CXX object CMakeFiles/test_webpage.dir/src/test_webpage.cpp.o
[100%] Linking CXX executable test_webpage
/usr/bin/ld: warning: libgomp-4f651535.so.1, needed by /data/qc_rebuild_webpage/Aoeiuv/extern/private/scenarios/webpage/qa/src/query_check_inference/…/…/…/…/…/…/…/extern/private/scenarios/webpage/common/libtorch/libtorch.so, not found (try using -rpath or -rpath-link)
[100%] Built target test_webpage