Go build failing due to "multiple definition of" error
Opened this issue · 4 comments
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
I think this may mean that your C compiler is too old, but I don't have a way to confirm that.
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.
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 addRUN scl enable devtoolset-7 bash
in the docker file but still its using gcc4 by default when thego build ...
is run.
Tried running source scl_source enable devtoolset-7
as well as mentioned here. But still no luck.
Sorry I don't know what to do with centos 7, I don't use that myself.