I try to call a C function pointer as a callback from a Go function but get a linker error I don't understand.
package main
/*
typedef void (*int_int)(int, int);
void bridge_int_int(int a, int b, int_int f){
f(a, b);
}
*/
import "C"
//export IntIntCallback
func IntIntCallback(a, b C.int, cb C.int_int) {
C.bridge_int_int(a, b, cb)
}
func main() {
// Noop, required to make CGO happy: `-buildmode=c-*` requires exactly one
// main package, which in turn needs a `main` function`.
}
The error is:
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/11.2.0/../../../../i686-w64-mingw32/bin/ld.exe: $WORK\b001\_x002.o: in function `bridge_int_int':
./test.go:6: multiple definition of `bridge_int_int'; $WORK\b001\_x001.o:/tmp/test.go:6: first defined here
collect2.exe: error: ld returned 1 exit status
I don't understand where this multiple definition problem comes from.