This is a creation in Article, where the information may have evolved or changed.
Recently on the imx6 to use go as a background service program, need to read serial data, want to use c to read the serial port data cgo
Package Main /* #cgo ldflags:lib/testrs232.a#include "Lib/testrs232.h"
int Opendev (char *buf) {int ret = Opendevice (BUF); return ret;}
int Writedev (char *buf,int writesize) { int ret = Writedevice (buf,writesize); return ret;}
int Setpara (enum Ebaud baud, enum Edatabit databit, enum Eparitybit paritybit, enum Estopbit stopbit) { Setparameter (baud,databit,paritybit,stopbit);}
int ReadData (char *buf,int bufsize) { Return Read_port (buf,bufsize);} */
Import "C"
In the above call, the/**/is in C code, followed by the import "C"
For example: Go to use the function above C.opendev (c.cstring ("/dev/ttymxc2"))Successfully compiled under Linux, and can read the value of the serial port, but want to compile to the arm platform on the board, always show errors, later in the Liteide, editing the current environment, will cgo_enabled=1, default cgo_enabled=0, recompile, or error, cannot find the compiler, later set environment variable CC, set as the tool chain of the board CC=ARM-FSL-LINUX-GNUEABI-GCC, compile successfully