Skip to content

Instantly share code, notes, and snippets.

@skelterjohn
Created August 8, 2011 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skelterjohn/1132444 to your computer and use it in GitHub Desktop.
Save skelterjohn/1132444 to your computer and use it in GitHub Desktop.
/*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