Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go build failing due to "multiple definition of" error #160

Open
dushyant7917 opened this issue Nov 23, 2022 · 4 comments
Open

Go build failing due to "multiple definition of" error #160

dushyant7917 opened this issue Nov 23, 2022 · 4 comments

Comments

@dushyant7917
Copy link

Getting below traceback while building go source code.

[2022-11-16T11:45:45.447Z] export CGO_ENABLED=1
[2022-11-16T11:45:45.447Z] go build -tags opa_wasm -o ./bin/opa_argus_metrics_linux_amd64 ./".gopath/src/git.soma.salesforce.com/opa-argus-metrics-plugin"/cmd/opa-argus-metrics-plugin/...
[2022-11-16T11:46:03.580Z] # git.soma.salesforce.com/Kuleana/opa-argus-metrics-plugin/.gopath/src/git.soma.salesforce.com/opa-argus-metrics-plugin/cmd/opa-argus-metrics-plugin
[2022-11-16T11:46:03.580Z] /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
[2022-11-16T11:46:03.580Z] /tmp/go-link-3790786405/000023.o: In function `assertions':
[2022-11-16T11:46:03.580Z] /tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:30: multiple definition of `assertions'
[2022-11-16T11:46:03.580Z] /tmp/go-link-3790786405/000022.o:/tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:30: first defined here
[2022-11-16T11:46:03.580Z] /tmp/go-link-3790786405/000025.o: In function `assertions':
[2022-11-16T11:46:03.580Z] /tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:30: multiple definition of `assertions'
[2022-11-16T11:46:03.580Z] /tmp/go-link-3790786405/000022.o:/tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:30: first defined here
[2022-11-16T11:46:03.580Z] /tmp/go-link-3790786405/000026.o: In function `assertions':

Found another similar issue, so tried using gcc7+ with centos7. But still got same error. After that tried using --ldflags '-extldflags "-Wl,--allow-multiple-definition"' flags along with go build but this time got below error.

[2022-11-22T12:02:21.391Z] export CGO_ENABLED=1
[2022-11-22T12:02:21.391Z] go build --ldflags '-extldflags "-Wl,--allow-multiple-definition"' -tags opa_wasm -o ./bin/opa_argus_metrics_linux_amd64 ./".gopath/src/git.soma.salesforce.com/opa-argus-metrics-plugin"/cmd/opa-argus-metrics-plugin/...
[2022-11-22T12:02:39.577Z] # git.soma.salesforce.com/Kuleana/opa-argus-metrics-plugin/.gopath/src/git.soma.salesforce.com/opa-argus-metrics-plugin/cmd/opa-argus-metrics-plugin
[2022-11-22T12:02:39.577Z] /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
[2022-11-22T12:02:39.577Z] /tmp/go-link-2410706016/000022.o: In function `assertions':
[2022-11-22T12:02:39.577Z] /tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:30: undefined reference to `static_assert'
[2022-11-22T12:02:39.577Z] /tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:31: undefined reference to `static_assert'
[2022-11-22T12:02:39.577Z] /tmp/go-link-2410706016/000023.o:/tmp/project/vendor/github.com/bytecodealliance/wasmtime-go/build/include/wasm.h:32: more undefined references to `static_assert' follow
@alexcrichton
Copy link
Member

I think this may mean that your C compiler is too old, but I don't have a way to confirm that.

@dushyant7917
Copy link
Author

dushyant7917 commented Nov 25, 2022

I think this may mean that your C compiler is too old, but I don't have a way to confirm that.

Yeah the problem is inspite of using a centos7 image that has gcc7 installed, by default the image uses gcc4 only. This I confirmed by running bash of the image. I had to run scl enable devtoolset-7 bash inside image to enable gcc7. But how can I do this by default for the image I'm using. Tried to add RUN scl enable devtoolset-7 bash in the docker file but still its using gcc4 by default when the go build ... is run.

@dushyant7917
Copy link
Author

I think this may mean that your C compiler is too old, but I don't have a way to confirm that.

Yeah the problem is inspite of using a centos7 image that has gcc7 installed, by default the image uses gcc4 only. This I confirmed by running bash of the image. I had to run scl enable devtoolset-7 bash inside image to enable gcc7. But how can I do this by default for the image I'm using. Tried to add RUN scl enable devtoolset-7 bash in the docker file but still its using gcc4 by default when the go build ... is run.

Tried running source scl_source enable devtoolset-7 as well as mentioned here. But still no luck.

@alexcrichton
Copy link
Member

Sorry I don't know what to do with centos 7, I don't use that myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants