How do I call C from Go using the "foreign function interface"
How do I use Go's "foreign function interface" to call out to a C function?
This interface is mentioned on 开发者_运维问答the FAQ, but I cannot see it mentioned elsewhere in the docs.
Check out this file from the Go repository. It shows how to wrap a C library in Go and has quite a few comments that explain the process.
Here is an article that demonstrates the following with Cgo:
To lead with an example, here's a Go package that provides two functions -
Random
andSeed
- that wrap C'srand
andsrand
functions.
精彩评论