The CGO of Golang learning

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.