0

My os is Kali, running GLIBC_2.32. I need to build an CGO application for a debian 10 system, which is running GLIBC_2.28.

If I go build with dynamic linking, it can't be run on the debian system, it shows GLIBC mismatch:

version `GLIBC_2.29` not found
version `GLIBCXX_3.4.29` not found
version `GLIBC_2.32` not found

So I tried static linking: CGO_LDFLAGS='-static' go build. A gui library uses OpenGL and it shows error:

# github.com/go-gl/gl/v3.2-core/gl
/usr/bin/ld: cannot find -lGL

After searching a while I found the libGL is related to the gpu driver and can't be statically linked.

Then I tried linking libGL.so dynamically and statically linking other libraries by:

CGO_LDFLAGS='-L/usr/lib/x86_64-linux-gnu -Bdynamic -lGL -static' go build

But same error: "cannot find -lGL"

I don't want to use docker, it's too heavy. And I don't think upgrading from debian 10 to 11 solves the problem, there maybe some other clients running different os in the future. What's the best solution?

aj3423
  • 2,003
  • 3
  • 32
  • 70
  • Even if statically linked, glibc needs to match on the host system (which is generally why you shouldn’t statically link glibc). There are some c libraries like musl intended for static linking. – JimB Dec 22 '21 at 03:56

1 Answers1

2

Then I tried linking libGL.so dynamically and statically linking other libraries by: CGO_LDFLAGS='-L/usr/lib/x86_64-linux-gnu -Bdynamic -lGL -static' go build

The -static flag tells the linker: perform a completely static link. It doesn't matter whether you put it before or after -lGL, the meaning is the same.

To link some libraries statically and link others dynamically, see this answer.

That said, what you are trying to do is impossible: if you have any dynamic libraries in your link, then libc.so.6 must also be dynamically linked.

I don't want to use docker, it's too heavy.

Too bad. You'll have to use docker, or set up a chroot environment, or build yourself a "Linux to older Linux" crosscompiler. The docker is likely easiest to implement.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362