Created
August 8, 2011 18:57
-
-
Save skelterjohn/1132444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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