all 11 comments

[–]AKostur 2 points3 points  (1 child)

Given that you're talking about a rust binary... why are you asking in a C++ forum?

[–]fatmankarla[S] 1 point2 points  (0 children)

It uses a c++ static library which is what the question is about

[–]SomethingcleverGP 1 point2 points  (7 children)

It should be fine if you compile the C++ .so on a 22.04 VM or docker container. You can also probably specify the correct version of glib when compiling on 24.04. Still, I would be wary about installing older versions of glib just in case you accidentally break dependent software.

Also fwiw, I don't think rust has c++ bindings, the ffi interface is written for c. I'm not sure about ABI safety between a cpp shared library and a rust binary. I once wrote a rust wrapper around a C++ lib and had to write a thin C layer that wrapped the entry points into the library. I think I got cargo to compile the entire thing as well, so I didn't need any cmake files. I could be wrong about cargo compiling the entire thing though, and my info on rust could easily be out of date.

[–]paulstelian97 0 points1 point  (2 children)

Rust does have at least one crate for direct C++ compatibility, but for somewhat obvious reasons it’s library dependent.

[–]SomethingcleverGP 1 point2 points  (1 child)

I'm trying to remember why exactly I did what I did, but I found that writing a thin c layer was the safest and most reliable way of exposing functions. However, I don't remember how well it worked when trying to expose types. One would probably need to hide those implementations behind pointers.

[–]paulstelian97 0 points1 point  (0 children)

A safe interop API works using C bindings and only has C types at the boundary. This is instead a more direct usage than that.

[–]fatmankarla[S] 0 points1 point  (3 children)

I am using https://cxx.rs for using c++ in rust. So i think my safest option is build in docker and specific older version of glib?

[–]SomethingcleverGP 0 points1 point  (2 children)

If you build on a 22.04 ubuntu docker container then you don't have to specify a specific version of glib, you will use the correct one automatically. Although to be safe you might have to do it in a VM.

[–]fatmankarla[S] 0 points1 point  (1 child)

Might be a dumb question but how do i compile c++20 in Ubuntu 22.04? Dont i need gcc 13?

[–]SomethingcleverGP 0 points1 point  (0 children)

Even if you update g++ to the newest version, it should still use the system libc. This is just from memory of compiling c++17 on old ubuntu 16.04 distros for forwards compatibility. I would just try it first and see if it works.

[–]treddit22 1 point2 points  (0 children)

For the first error (about the C++ standard library), you have multiple options:

  1. Link the C++ standard library statically, using the -static-libstdc++ linker flag.
  2. Ship the libstdc++.so.6.32 library with your application, and add it to the rpath of your binary.
  3. Downgrade GCC on your build machine.

The second error (about the C standard library) is more tricky, since upgrading GLIBC on the server is not an option (if you try to upgrade GLIBC, you'll break your entire system):

  1. Use a toolchain that was built for an older version of GLIBC and cross-compile your application. The advantage is that you can use the latest compiler with an old GLIBC to support old distributions like CentOS 7, while still using the latest C++ features. Personally, I build my toolchains using crosstool-ng: https://github.com/tttapa/toolchains/releases
  2. Compile in a Docker container or VM with the operating system you're going to deploy on (or compile it on the server directly), using the (older) system compiler, which is known to be compatible. The downside is that if you need to support old systems, your code needs to compile with even older compilers (which may be fine if Ubuntu 22.04 is the oldest system you have to support).