开发者

How do I call C from Go using the "foreign function interface"

开发者 https://www.devze.com 2022-12-28 21:05 出处:网络
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 thi

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 and Seed - that wrap C's rand and srand functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消