You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a hello1/lib/hello1.c library and built it into hello1/lib/libhello1.a
#include<stdio.h>voidhello() {
printf("Hello from C hello1.c\n");
}
hello2.c:
I have a hello2/lib/hello2.c library with the same function name hello that in hello1.c and built it into hello2/lib/libhello2.a
#include<stdio.h>voidhello() {
printf("Hello from C hello2.c\n");
}
hello1.go:
I have a hello1/hello1.go and built it into hello1/hello1.so with go build -buildmode=plugin
package main
/*#cgo LDFLAGS: -L${SRCDIR}/lib -lhello1void hello();*/import"C"import"fmt"funcHello() {
fmt.Println("Hello from Go plugin hello1.go")
fmt.Println("Call C hello1.c")
C.hello()
}
hello2.go:
I have a hello2/hello2.go and built it into hello2/hello2.so with go build -buildmode=plugin
package main
/*#cgo LDFLAGS: -L${SRCDIR}/lib -lhello2void hello();*/import"C"import"fmt"funcHello() {
fmt.Println("Hello from Go plugin hello2.go")
fmt.Println("Call C hello2.c")
C.hello()
}
main.go:
I have a main.go in the root project dir and built it into main with go build.
Load Go plugin hello1.so
Load Go plugin hello2.so
Call Go plugin hello1.go
Hello from Go plugin hello1.go
Call C hello1.c
Hello from C hello1.c
Call Go plugin hello2.go
Hello from Go plugin hello2.go
Call C hello2.c
Hello from C hello2.c
What did you see instead?
I see Hello from C hello1.c at the last line but I expected Hello from C hello2.c
Load Go plugin hello1.so
Load Go plugin hello2.so
Call Go plugin hello1.go
Hello from Go plugin hello1.go
Call C hello1.c
Hello from C hello1.c
Call Go plugin hello2.go
Hello from Go plugin hello2.go
Call C hello2.c
Hello from C hello1.c
The text was updated successfully, but these errors were encountered:
dsxack
changed the title
Plugins can't use different CGO libraries with the same symbol names
Plugins can't use different C libraries by CGO with the same symbol names
Nov 27, 2020
If you only load hello2.so does it print what you expect?
Have you tried using __attribute__ ((visibility ("hidden"))) on the C functions with the same name?
Add -fvisibility=hidden gcc flag when to C libraries compile resolves my issue.
Load Go plugin hello1.so
Load Go plugin hello2.so
Call Go plugin hello1.go
Hello from Go plugin hello1.go
Call C hello1.c
Hello from C hello1.c
Call Go plugin hello2.go
Hello from Go plugin hello2.go
Call С hello2.c
Hello from C hello2.c
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
)?go env
OutputWhat did you do?
hello1.c:
I have a
hello1/lib/hello1.c
library and built it intohello1/lib/libhello1.a
hello2.c:
I have a
hello2/lib/hello2.c
library with the same function namehello
that inhello1.c
and built it intohello2/lib/libhello2.a
hello1.go:
I have a
hello1/hello1.go
and built it intohello1/hello1.so
withgo build -buildmode=plugin
hello2.go:
I have a
hello2/hello2.go
and built it intohello2/hello2.so
withgo build -buildmode=plugin
main.go:
I have a
main.go
in the root project dir and built it intomain
withgo build
.What did you expect to see?
What did you see instead?
I see
Hello from C hello1.c
at the last line but I expectedHello from C hello2.c
The text was updated successfully, but these errors were encountered: