Search code examples
gobuildglibcdynamic-linkinglibc

Go build with another glibc


I have installed another version of GLIBC and want to compile Golang code against this new GLIBC.

I have tried the following command for dynamic compilation:

go build --ldflags '-linkmode external -L /path/to/another_glibc/

But when I run ldd "go_executable", it still shows linked to default glibc.

Output:

linux-vdso.so.1 =>  (0x00007fff29da7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f128a93c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f128ad06000)

Expected Output:

linux-vdso.so.1 =>  (0x00007fff45fa7000)
libc.so.6 => /another_glibc/lib/libc.so.6 (0x00007f5cd2067000)
/another_glibc/ld-2.29.so => /lib64/ld-linux-x86-64.so.2 (0x00007f5cd2420000)

What is missing here?


Solution

  • Before doing go build Set

    CGO_LDFLAGS

    Dynamic:

    export CGO_LDFLAGS="-Xlinker -rpath=/path/to/another_glibc/lib"
    

    Static:

    export CGO_LDFLAGS="-Xlinker -rpath=/path/to/another_glibc/lib -static"
    

    CGO_LDFLAGS lets you set GCC-like ld flags for Go.