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

2

26

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.

Franchot answered 29/4, 2010 at 19:45 Comment(1)
See also https://mcmap.net/q/125884/-how-to-use-c-in-goPrague
D
18

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.

Dermatoid answered 29/4, 2010 at 20:2 Comment(1)
That's a very well documented file! I had begun writing an answer but decided to check that file out and then deleted my unfinished answer after reading.Pampa
G
2

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.

Gifferd answered 30/7, 2013 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.