-
Notifications
You must be signed in to change notification settings - Fork 18k
cgo: duplicate definition linking cgo program with c-archive cgo library #49256
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
Comments
I am not sure whether CGO is designed to support this use case. Both the main program and the c-archive library here use CGO. Also interesting in that this error is taking place before we ever invoke the Go linker. @ianlancetaylor might be able to offer some insights here. |
Code built with |
@ianlancetaylor it's very useful to me,ex:package some different version c-shared library in docker. |
Perhaps it is useful (although I don't see why), but that doesn't really matter considering that I don't see any way to implement it. As you observe, it doesn't work, and there really isn't any way to make it work. |
thanks your reply //hello.go import "C" func main() { //export Hello |
Yes, there are very limited cases in which it can work. But in general it won't. |
Hi, I have a similar scenario where I have 2 libraries build with cgo as c-archive for 2 different flutter libraries, and when both are installed in the same project return this error
|
I have the same issue. I have 2 different go libraries compiled into ios arm64 static libraries and I link both to the same project. Both have go runtime symbols and therefore conflict when copying to a final app binary |
I have the same issue in the same scenerio. could u plz tell me how u fix it. ? |
We went with a dynamic wrapper over a static library so we had 1 static and 1 dynamic. Go runtime started crashing and we decided to move all libraries to a go-client monorepo and have them merged into one static framework. It will allow us to introduce more go libraries that we share across BE, FE, Android and iOS. FE uses wasm, BE directly imports dependencies from the monorepo, ios is compiled in 1 big static library, android is compiled in 1 big dynamic library |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
//hello.go
package main
import "C"
import "fmt"
func main() {
// Hello("hello")
}
//export Hello
func Hello() {
fmt.Println("output:")
}
//run.go
package main
/*
#include "libhello.h"
#cgo CFLAGS: -I./dist/
#cgo LDFLAGS: -L./dist/ -lhello
*/
import "C"
func main() {
C.Hello()
}
step1
go build --buildmode=c-archive -o ./dist/libhello.so hello.go
step2
go run run.go
What did you expect to see?
output:
What did you see instead?
duplicate symbol '__cgo_panic' in:
$WORK/b001/_cgo_main.o
./dist/libhello.so(go.o)
duplicate symbol '__cgo_topofstack' in:
$WORK/b001/_cgo_main.o
./dist/libhello.so(go.o)
duplicate symbol '_crosscall2' in:
$WORK/b001/_cgo_main.o
./dist/libhello.so(go.o)
duplicate symbol '__cgo_wait_runtime_init_done' in:
$WORK/b001/_cgo_main.o
./dist/libhello.so(000006.o)
ld: 4 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The text was updated successfully, but these errors were encountered: