Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*cgopkg.go*/
package cgopkg
//#include <stdlib.h>
//#include "cgopkg.h"
import "C"
import (
"unsafe"
)
func Foo() {
chi := C.CString("hi")
defer C.free(unsafe.Pointer(chi))
C.fooprint(chi)
}
/*cgopkg.h*/
void fooprint(char* s)
/*cgopkg.c*/
#include <stdio.h>
void fooprint(char* s) {
printf("%s\n", s)
}
/*Compile errors*/cgopkg.go:13:9: unable to find value of constant C.CString
cgopkg.go:13:9: call of non-function C.CString
cgopkg.go:14:8: unable to find value of constant C.free
cgopkg.go:14:8: call of non-function C.free
cgopkg.go:15:2: unable to find value of constant C.fooprint
cgopkg.go:15:2: call of non-function C.fooprint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.