I have project with C and C++ code which I want to build as single .so
library and use it in my Java program with Panama.
On my computer it works fine, but in CI it fails because of GLIBC
and GLIBCXX
version mismatch.
AFAIK better way to fix it is static linking.
And I found flags to statically link GLIBCXX
: -static-libgcc -static-libstdc++
.
But GLIBC
doesn't support static linking. And fails on build with -static
flag like this:
usr/bin/ld: /lib/x86_64-linux-gnu/libc.a(malloc.o): relocation R_X86_64_TPOFF32 against `tcache' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: failed to set dynamic section sizes: bad value
I know there is libc
implementation in llvm which supports static linking. But I can't find a way how to force clang use it, something like -static-llvm-libc
.
Also there are musl
which supports static linking too.
But flag --target=x86_64-unknown-linux-musl
doesn't force to use it somehow. And build with -static
still fails and I see with ldd
glibc
in dependencies.