confluentinc / confluent-kafka-go

Confluent's Apache Kafka Golang client
Apache License 2.0
4.65k stars 659 forks source link

Build error when generating the executable #570

Open sathishcaffeine opened 3 years ago

sathishcaffeine commented 3 years ago

Description

When we are trying to build our go application we are getting the below error.

Run this command env GOOS=linux go build <path to main package file> to see the error.

# github.com/caffeinetv/kafka-client-lib-go/producer
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/producer/events.go:19:28: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".Event
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/producer/events.go:33:28: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".Message
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/producer/producer.go:12:12: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".Producer
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/producer/producer.go:52:12: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".NewProducer
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/producer/producer.go:77:40: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".ConfigMap
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/producer/producer.go:78:9: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".ConfigMap
note: module requires Go 1.15
# github.com/caffeinetv/kafka-client-lib-go/consumer
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/consumer/consumer.go:12:12: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".Consumer
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/consumer/consumer.go:53:13: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".NewConsumer
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/consumer/consumer.go:79:40: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".ConfigMap
../../go/pkg/mod/github.com/caffeinetv/kafka-client-lib-go@v0.0.0-20200924045908-d511f0207433/consumer/consumer.go:80:9: undefined: "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka".ConfigMap
note: module requires Go 1.15

How to reproduce

Checklist

Please provide the following information:

Sreevani871 commented 3 years ago

Facing the same issue. Any update on how to fix it?

edenhill commented 3 years ago

What OS are you running the GOOS=linux go build command on?

edenhill commented 3 years ago

Cross-compilation is not supported, if you are building on OSX for Linux you will need to build it in a Linux docker container.

Sreevani871 commented 3 years ago

Actually, I am facing two different errors. OSX Environment

/Users/sreevani/go/pkg/mod/github.com/confluentinc/confluent-kafka-go@v1.5.2/kafka/kafka.go:257:2: cannot find package
make: *** [build] Error 1
this is related to librdkafka package is not found.

CircleCI Env:

Docker Engine Version: 18.09.6
Kernel Version: Linux d626114d7ea9 4.15.0-1077-aws #81-Ubuntu SMP Wed Jun 24 16:48:15 UTC 2020 x86_64 Linux
golang:1.15

Error:

go test ./... GOARCH 386 in ./instrumentation/github.com/confluentinc/confluent-kafka-go/kafka/otelkafka
# go.opentelemetry.io/contrib/instrumentation/github.com/confluentinc/confluent-kafka-go/kafka/otelkafka
./consumer.go:28:24: undefined: kafka.ConfigMap
./consumer.go:38:2: undefined: kafka.Consumer
./consumer.go:40:14: undefined: kafka.Event
./consumer.go:45:22: undefined: kafka.Consumer
./consumer.go:54:47: undefined: kafka.Event
./consumer.go:88:35: undefined: kafka.Message
./consumer.go:128:34: undefined: kafka.Event
./consumer.go:134:47: undefined: kafka.Event
./message.go:25:7: undefined: kafka.Message
./message.go:31:29: undefined: kafka.Message
./message.go:31:29: too many errors
make: *** [Makefile:123: test-386] Error 2
edenhill commented 3 years ago

The latter error looks like a cross-compilation thing, guessing that any setting of GOARCH or GOOS that doesnt match the current platform will disable CGO_ENABLED, and that's what prevents the definition of kafka.XXXX.

The former is weird, try removing the confluent-kafka-go from go/pkg/mod/github.. and try again.

Sreevani871 commented 3 years ago

The latter error looks like a cross-compilation thing, guessing that any setting of GOARCH or GOOS that doesnt match the current platform will disable CGO_ENABLED, and that's what prevents the definition of kafka.XXXX.

Thanks @edenhill

duclm2609 commented 3 years ago

I face the same issue. I use an Alpine docker image to build on my Mac. I've tried to follow the instruction on README file but still no luck.

JY226 commented 3 years ago

facing the same issue so I did a temporary solution by writing dockerfiles for kafka related images

andriihrachov commented 3 years ago

switched do debian - it helped

1cergey commented 2 years ago

Hi! We use alpine image for build, have a same problem: "undefined: kafka.****" Did you resolve it? We want use this lib, but we will be forced to use a different library, like sarama