如何使用“外部函数接口”从Go中调用C代码?

huangapple go评论95阅读模式
英文:

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

问题

我如何使用Go的"外部函数接口"来调用C函数?

这个接口在FAQ中提到,但我在文档的其他地方没有看到它被提到。

英文:

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.

答案1

得分: 18

请查看Go仓库中的此文件。它展示了如何在Go中封装一个C库,并有很多解释该过程的注释。

英文:

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.

答案2

得分: 2

这是一篇文章,演示了使用Cgo实现以下功能:

举个例子,这是一个Go包,提供了两个函数 - RandomSeed,它们封装了C语言的randsrand函数。

英文:

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.

huangapple
  • 本文由 发表于 2010年4月30日 03:45:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/2740315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定