来源:https://stackoverflow.com/questions/17390117/reducing-the-version-of-libc-required
原回答
If you want to use the newer library you have two options 1. statically link libstdc++. 1. distributing your version of the library with the binary and using RPATH while linking. You can statically link with g++ using the
-static-libgcc -static-libstdc++ -static
this should pretty much statically link everything but will enlarge your binary.Another option is using RPATH the
-rpath
linker option can be passed like so :
-Wl,-rpath,$PATH
replacing$PATH
with something like libs or maybe just . for same directory as binary this way the header of the generated ELF (executable) will know where to look for the shared libraries required and you can just redistribute the shared libraries with your binary.otherwise you could just compile and link with the version supported on your target machines.
在 cmake 中指定静态链接
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static")