fluent-bit
fluent-bit copied to clipboard
How to develop a Go plugin and compile it into a .so file using static linking.
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
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.
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.
This issue was closed because it has been stalled for 5 days with no activity.