Getting started with golang's cgo
·1 min
/*
#cgo LDFLAGS: -framework CoreFoundation
#include <CoreFoundation/CoreFoundation.h>
*/
Cgo recognizes the above comments. Lines starting with #cgo are
removed and passed to the compiler.
What remains (aka the preamble) is used as a header when
compiling C parts of the package. import "C" must
immediately follow the preamble.
When using //exports, which exports a go function to C, the C code
in the comment (preamble) can include only declarations not definitions.
Except you can use static inline as a workaround for
simple functions.