This is a creation in
Article, where the information may have evolved or changed.
package main/*#include <stdio.h>#include <stdlib.h>*/import "C"import "unsafe"func main() {cstr := C.CString("HELLO, WORLD")C.puts(cstr)C.free(unsafe.Pointer(cstr))}
Tell me about the pit I met.
Although go in the format of strict requirements, but some places really not very humane, do not know is my operation has a problem, or how, hey
Attention:
I use the IDE is liteide, write code tried to compile several times, all error, error is as follows:
# TESTGCC
Could not determine kind of name for C.free
Could not determine kind of name for c.puts
It is important to note that:
/*
#include <stdio.h>
#include <stdlib.h>
*/
Import "C"
Import "unsafe"
Import "C" with the above C code cannot have extra blank lines, and import "C" must be the first import.
There is also a problem, when we need to rely on a non-C standard library? If you follow the above method, there will be a link error.
Workaround:
1. The first method
/*
#cgo CFLAGS:-I.
#cgo ldflags:-L. -lrtmp
#include <stdlib.h>
#include "Rtmp.h"
*/
Import "C"
2. The second method
/*
#cgo pkg-config:rtmp Cairo
#include "Rtmp.h"
*/
Import "C"