How to select the right gcc version when build with libtorch cxx11?

username: 111453
cooked: <p>I have met the same issue as <a href="https://github.com/pytorch/pytorch/issues/49460" class="inline-onebox" rel="noopener nofollow ugc">Libtorch: Segmentation fault when running torch::jit::load · Issue #49460 · pytorch/pytorch · GitHub</a>, when I use <code>std::regex</code>.<br>
It seems the symbol<br>
<code>_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE</code><br>
was binded to wrong file from<br>
<code>torch/csrc/jit/serialization/import_source.cpp:attributeAssignmentSpecialHandlingHack</code>:</p>
<pre><code class="lang-auto">    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=./build/libtorch_app [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/home/none/builds/app/libtorch/lib/libtorch.so [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/home/none/builds/app/libtorch/lib/libc10.so [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/usr/lib/x86_64-linux-gnu/libcuda.so.1 [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/usr/local/cuda/lib64/libnvrtc.so.11.1 [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/usr/local/cuda/lib64/libnvToolsExt.so.1 [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/usr/local/cuda/lib64/libcudart.so.11.0 [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/home/none/builds/app/libtorch/lib/libc10_cuda.so [0]
    197269:     symbol=_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE;  lookup in file=/home/none/builds/app/cxx11/usr/local/lib/libtorch_app.so [0]
    197269:     binding file /home/none/builds/app/libtorch/lib/libtorch_cpu.so [0] to /home/none/builds/app/cxx11/usr/local/lib/libtorch_app.so [0]: normal symbol `_ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE'
</code></pre>
<p>More informations:</p>
<pre><code class="lang-auto">$c++filt _ZSt13regex_replaceISt20back_insert_iteratorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEN9__gnu_cxx17__normal_iteratorIPKcS6_EENS1_12regex_traitsIcEEcET_SF_T0_SG_RKNS1_11basic_regexIT2_T1_EEPKSI_NSt15regex_constants15match_flag_typeE
std::back_insert_iterator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; std::regex_replace&lt;std::back_insert_iterator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char const*, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::__cxx11::regex_traits&lt;char&gt;, char&gt;(std::back_insert_iterator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char const*, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char const*, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::__cxx11::basic_regex&lt;char, std::__cxx11::regex_traits&lt;char&gt; &gt; const&amp;, char const*, std::regex_constants::match_flag_type)

$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ls libtorch-cxx11-abi-shared-with-deps-1.8.1+cu111.zip
libtorch-cxx11-abi-shared-with-deps-1.8.1+cu111.zip
</code></pre>
<p>I think the root cause may be I have used a different gcc version from libtorch-cxx11. Could someone help me?</p>

username: ptrblck
cooked: <p>I think you might be running into <a href="https://github.com/pytorch/pytorch/issues/49460">this issue</a> so could you please update the GitHub issue with your use case?</p>