package C /* // C 标志io头文件,你也可以使用里面提供的函数 #include #include #include #define LEN 1024 void pri(){ printf("Welcome to the C World!\n"); } int add(int a,int b){ return a+b; } char* Foo( char *input ) { char* res = malloc( LEN * sizeof( char ) ); sprintf( res, "%s %s", input, "World!" ); return res; } */ import "C" // 切勿换行再写这个 import ( "fmt" "unsafe" ) func Getpri() { C.pri() } func GetAdd() { fmt.Println(C.add(2, 1)) } func GetFoo(a string) { cs := C.CString(a) res := C.Foo(cs) str := C.GoString(res) C.free(unsafe.Pointer(cs)) C.free(unsafe.Pointer(res)) fmt.Println(str) } func main() { GetFoo("111") }