confluentinc / confluent-kafka-go

Confluent's Apache Kafka Golang client
Apache License 2.0
4.66k stars 658 forks source link

Failed to build confluent-kafka-go on arm64 machine. #1176

Open ahan-ai opened 7 months ago

ahan-ai commented 7 months ago

Description

I use github.com/confluentinc/confluent-kafka-go/v2@v2.3.0 in my project, which needs to be compiled on arm64 machine.

I use the go build command to build the binary, like: GOOS=linux CGO_ENABLED=1 GOARCH=arm64 go build -ldflags=-s -w -X 'main.BuildTime=' -X 'main.GitBranch=multi_arch' -X 'main.GitCommit=xxxxxxxxx' -X 'main.GoVersion=' -o output/backup-mgr cmd/mgr/main.go

The error messages are shown below:

/usr/local/go/pkg/tool/linux_arm64/link: running gcc failed: exit status 1 /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_mock.o): In function rd_kafka_mock_connection_write_out': (.text+0xd94): undefined reference toaarch64_ldadd4_acq_rel' /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_mock.o): In function rd_kafka_mock_connection_close': (.text+0xf60): undefined reference to__aarch64_ldadd4_acq_rel' /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_mock.o): In function rd_kafka_mock_connection_close': (.text+0xf88): undefined reference toaarch64_ldadd4_acq_rel' /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_mock.o): In function rd_kafka_mock_cluster_thread_main': (.text+0x11f0): undefined reference toaarch64_ldadd4_acq_rel' /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_mock.o): In function rd_kafka_mock_cluster_thread_main': (.text+0x130c): undefined reference toaarch64_ldadd4_acq_rel' /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_mock.o):(.text+0x14f0): more undefined references to __aarch64_ldadd4_acq_rel' follow /opt/tiger/compile_path/pkg/mod/github.com/confluentinc/confluent-kafka-go/v2@v2.3.0/kafka/librdkafka_vendor/librdkafka_glibc_linux_arm64.a(rdkafka_txnmgr.o): In functionrd_kafka_txn_op_commit_transaction.part.0': (.text+0x4170): undefined reference to `__aarch64_ldadd8_acq_rel'

My go env: GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/opt/tiger/.cache/go-build" GOENV="/tmp/.config-cof63mlelf3dpgqrls40/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/opt/tiger/compile_path/pkg/mod" GONOPROXY="gitlab.everphoto.cn,sysrepo.byted.org,git.smartisan.com" GONOSUMDB="code.byted.org,gitlab.everphoto.cn,git.byted.org,sysrepo.byted.org,git.smartisan.com" GOOS="linux" GOPATH="/opt/tiger/compile_path" GOPRIVATE="gitlab.everphoto.cn,sysrepo.byted.org,git.smartisan.com" GOPROXY="https://goproxy.byted.org,direct" GOROOT="/usr/local/go" GOSUMDB="off" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64" GOVCS="" GOVERSION="go1.20.14" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/opt/tiger/compile_path/src/code.byted.org/infcs/vebackup-core/go.mod" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3739323652=/tmp/go-build -gno-record-gcc-switches"

How to reproduce

I am not pretty sure if other people can reproduce it, but I can reproduce it in my machine.

Checklist

Please provide the following information:

milindl commented 6 months ago

@ahan-ai , I'll take a look at this issue. I couldn't reproduce it locally but I was using an amd64 system and cross compiling to arm64.

Could you try this, set the CGO_LDFLAGS environment variable to "-latomic" and see if that works for you? CGO_LDFLAGS="-latomic"

milindl commented 6 months ago

And also, what is the version of gcc on your machine which is used for linking?