I am trying to test build a shared C lib in GoLang, and the output does not create a header file (.h)
test.go:
package main
import "C"
import "fmt"
func ExportedFun(s string) {
fmt.Printf("C gave us %s string", s)
}
func main() {}
and the command I run is:
go build -buildmode=c-shared -o test.so test.go
I get the .so
file but no header file. Is there something I am missing?
From the go command documentation:
The only callable symbols will be those functions exported using a cgo //export comment.
Th syntax for exporting a function via cgo can be found in the cgo documentation
Go functions can be exported for use by C code in the following way:
//export MyFunction func MyFunction(arg1, arg2 int, arg3 string) int64 {...} //export MyFunction2 func MyFunction2(arg1, arg2 int, arg3 string) (int64, *C.char) {...}
Marking your function as exported will generate the header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With