Error run rust application

Hello everyone I put the project together on my computer, uploaded it to the server and got:
/lib64/libstdc++.so.6: version GLIBCXX_3.4.29' not found //lib64/libc.so.6: version GLIBC_2.29' not found
/lib64/libc.so.6: version `GLIBC_2.38'

Does anyone know how to compile so that all these dependencies are included in the binary?

I think this is a C++ problem.

either configure the C++ code to statically link libstdc++, or make sure you have the same version of libstdc++ installed both locally and on the server.

How do I make a static link? I tried to use musl build, but I got the error that there is no c++...

rust will by default statically link all dependency crates. switching to the musl target changes the default of libc linkage, but you'll also need special C++ toolchain to target the musl libc.

your problem is not about rust, it's whatever C++ library you are using that is causing the problem. libstdc++ is the GNU C++ standard library, rust by itself don't use libstdc++, only C++ code needs it.

find out which of your dependencies uses a C++ ffi library, and check their documentation to see if it's possible to change the C++ build configurations.

1 Like

Targeting the right version of glibc is a pain. Binaries aren't guaranteed to be portable between Linux distros or even different versions of the same distro (this is true in general, not specific to Rust).

The easiest solution is to compile inside a VM or a container that has the same OS version as your server.

Compiling for a MUSL target will work too, if your binary is statically linked and you ensure it doesn't use any C dependencies that aren't on your target system. In Rust, look for -sys crates in cargo tree output, and check their documentation to see if they support static linking and how to enable it.

Thanks for helping me.

My problem solved when i did next steps:

  1. Copy 4 libs to target OS from OS where i builded application:
  • libc.so.6
  • libstdc++.so.6
  • libm.so.6
  • ld-linux-x86-64.so.2
  1. Install pathelf (centos example)
yum update
yum install patchelf
  1. Patch our binnary
pathelf patchelf --set-interpreter /NEW_PATH/ld-linux-x86-64.so.2 ./my_application
  1. Run
LD_LIBRARY_PATH="/NEW_PATH" LD_PRELOAD="/NEW_PATH/libc.so.6 /NEW_PATH/libstdc++.so.6 /NEW_PATH/libm.so.6" ./my_application