I am trying to write a shared module that will be called from C, but I
have run into a problem in using the work-around in
https://github.com/golang/go/wiki/cgo#the-basics for calling variadic C
functions.
The case that I have is more complex, but altering the example at the
wiki demonstrates the problem; the function definition that is used to
call on to printf appears more than once in the C code generated by
Cgo.
```
~/src/
github.com/kortschak/cgo $ cat cgo.go
package main
/*
#include <stdio.h>
#include <stdlib.h>
void myprint(char* s) {
printf("%s\n", s);
}
*/
import "C"
import "unsafe"
//export Example
func Example() {
cs := C.CString("Hello from stdio\n")
C.myprint(cs)
C.free(unsafe.Pointer(cs))
}
func main() {}
~/src/
github.com/kortschak/cgo $ go build -o cgo.so -buildmode=c-shared
.
#
github.com/kortschak/cgo
/tmp/go-build899365101/b001/_x002.o: In function `printf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:104: multiple definition of
`myprint'
/tmp/go-build899365101/b001/_x001.o:/usr/include/x86_64-linux-
gnu/bits/stdio2.h:104: first defined here
collect2: error: ld returned 1 exit status
```
Removing the "//export Example" comment prevents this failure, but then
obviously also loses the exported function. I have tried protecting the
function in a #ifndef/#endif, to no avail.
Is it reasonable for me to expect this to work? If so, what am I doing
wrong?
thanks
Dan