fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

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

Open LegendaryGasai opened this issue 7 months ago • 1 comments

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

LegendaryGasai avatar Apr 08 '25 05:04 LegendaryGasai

That is not static linking there, your example is explicitly doing shared linking and also doing it with libc enabled. You need disable CGO at least.

patrick-stephens avatar Jun 03 '25 11:06 patrick-stephens

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the exempt-stale label.

github-actions[bot] avatar Sep 07 '25 02:09 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Oct 25 '25 02:10 github-actions[bot]