On Tue, Oct 1, 2019 at 7:36 PM <dr.ch.mau...@gmail.com> wrote: > > what is wrong with the following simple code, which yields "undefined > reference for F" ? > > > file f.go: > > package main > // #include "f.h" > // void f (int a) { F(a) } > import "C" > > func F(a int) { println(a) } > func main() { C.f(7) } > > > file f.h: > > extern void F (int a); > > //export F
Putting "//export F" in f.h isn't going to do anything. A "//export" comment has to appear just before the Go function that you want to export. Note that as explained at https://golang.org/cmd/cgo, "Using //export in a file places a restriction on the preamble: since it is copied into two different C output files, it must not contain any definitions, only declarations." In the above f.go, "void f (int a) { F(a) }" is a definition. So you can't use that in conjunction with an "//export" comment. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWODXnv267tcTsPSrf0JYs4OzNsrhd0Nr5n5a%2By-TaSyA%40mail.gmail.com.