How to avoid introducing `GLIBCXX_3.4.26` symbols when building with gcc 9.5.0

I built a module (so file, dynamic library) upon libtorch and I find even I utilize some calls like std::string::data() and build with gcc 9.5.0(the symbol version is GLIBCXX_3.4.26), no GLIBCXX_3.4.26 symbol is found in the built so file. But if I build another so which calls the same functions, it contains symbols such as GLIBCXX_3.4.26 _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv. The main difference may lie in the build options though they both uses gcc 9.5.0. The first one leverages torch cxx flags: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}").

So I am wondering if this is the reason. and if yes, how to avoid introducing GLIBCXX_3.4.26?

Or a more general questions, how to make sure the library that is built with gcc 9.5.0 can run on ubuntu 18.04 or OS that has installed gcc 7(the glibcxx is 3.4.24)?