Skip to content

How to develop a Go plugin and compile it into a .so file using static linking. #10181

Open
@LegendaryGasai

Description

@LegendaryGasai

Fluent-bit provides the ability to develop plugins using Go(https://docs.fluentbit.io/manual/development/golang-output-plugins), and then compile them into a shared library with the command:

go build -buildmode=c-shared -o out_gstdout.so out_gstdout.go

to run custom plugins. However, due to differences in the base libraries, such as the version of glibc between the runtime and build environments, the out_gstdout.so file may not work properly on other hosts.

Are there any possible solutions? I have tried using musl static linking, but it doesn't seem to work.

#!/bin/bash

export CC=musl-gcc
export CGO_ENABLED=1

go build -buildmode=c-shared -o out_gstdout.so .

[2025/04/08 13:31:20] [error] [proxy] error opening plugin ./out_gstdout.so: '/lib/x86_64-linux-gnu/libc.so: invalid ELF header'
[2025/04/08 13:31:20] [error] [plugin] error loading proxy plugin: ./out_gstdout.so

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions