2

I am working on an Apache2 web server module written in Rust.

I have managed to compile the and get a .so file but when I move the library to another docker image and try to include it in the httpd.conf file I get the following error:

httpd: Syntax error on line 190 of /etc/httpd/conf/httpd.conf: Cannot load modules/libmod_hello.so into server: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /etc/httpd/modules/libmod_hello.so)

I probably should be able to make this work on that server by compiling the code against version 2.18 of GLIBC but doing that I will have to compile the code against all available GLIBC versions out there and that is obviously not practical.

Is there any way I can statically link my library to glibc so that I can deploy the library on different apache servers?

I added the following lines to config.toml

[build]
rustflags = ["-C", "target-feature=+crt-static"]
target = "x86_64-unknown-linux-gnu"

but now I get the following error:

error: cannot produce dylib for `mod_hello v0.0.2 (/src/examples/mod_hello)` as the target `x86_64-unknown-linux-gnu` does not support these crate types
Reza
  • 1,478
  • 1
  • 15
  • 25
  • Static linking to glibc doesn't work this way, don't do this. – n. m. could be an AI Nov 04 '21 at 05:49
  • 2
    Rumor has it that statically linking glibc is pain. Building/linking with musl [probably](https://stackoverflow.com/q/62786812/401059) also causes heaps of problems, and I doubt you can avoid these problems by having two different glibcs loaded in one executable. Your best bet is to build against the present or an older glibc. In theory, glibc provides backward compatibility, and your built library should continue to work even when updating glibc. (In practice, there may of course be [problems](https://abi-laboratory.pro/?view=timeline&l=glibc) with this, but they are rare.) – Caesar Nov 04 '21 at 06:08
  • I agree with Caesar -- " but doing that I will have to compile the code against all available GLIBC versions out there and that is obviously not practical" seems to be a misunderstanding. In practice just need to compile on an older distro to have forward compaibility for your shared library. – covener Nov 09 '21 at 13:39

0 Answers0