C language uses multiple go static libraries, reporting duplicat symbols error
file hello.go
// file hello.go
package main
import "C"
func main() {}
//export hello
func hello() { println("hello") }
file world.go
// file world.go
package main
import "C"
func main() {}
//export world
func world() { println("world") }
build command
platform: darwin
build command:
go build -buildmode c-archive -o libhello.a hello.go
go build -buildmode c-archive -o libworld.a world.go
files:
libhello.h libhello.a libworld.h libworld.a hello.go world.go
file main.c
// file main.c
#include "libhello.h"
#include "libworld.h"
int main()
{
hello();
world();
}
build command:
gcc -o cc -L. -lhello -lworld main.c
The error is
duplicate symbol '__cgo_panic' in: ./libhello.a(go.o) ./libworld.a(go.o) duplicate symbol '__cgo_topofstack' in: ./libhello.a(go.o) ./libworld.a(go.o) duplicate symbol '_crosscall2' in: ./libhello.a(go.o) ./libworld.a(go.o) ld: 3 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Using a dynamic library will not report this error, but I need to use a static library