接口与围棋C库 [英] Interface Go with C libraries

查看:219
本文介绍了接口与围棋C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何一个接口的围棋程序用C语言库?

我已经浏览Go的源$ C ​​$ C,但我还是没有想出来。如果有人已经这样做了,你可以分享吗?

更新:感谢@fserb,我从转到来源张贴一些文档:


  

CGO使围棋的创建
  调用C code型包。


  
  

用法:CGO [编译器选项] file.go


  
  

编译器选项传递
  通过uninter preTED调用时
  GCC编译器的的C部分
  包。


  
  

输入file.go是语法
  一个导入有效围棋源文件
  伪包的C,然后指
  类型,如C.size_t,变量如
  作为C.stdout,或诸如功能
  C.putchar。


  
  

如果的C导入立即
  通过评论pceded $ P $,这则留言是
  编译C当用作首标
  包的部分。例如:


  
  

  //的#include<&stdio.h中GT;
//#包括LT&;&errno.h中GT;
进口C


  
  

CGO将输入到文件
  四个输出文件:二围棋源
  文件,6C一个C文件(或8C或者5C),
  和C文件GCC。


  
  

标准包装的makefile规则
  Make.pkg自动使用过程中
  CGO。见$ GOROOT /其它/ CGO /标准输入输出和
  $ GOROOT的例子/其它/ CGO / GMP。


  
  

CGO尚不支持gccgo工作。



解决方案

。另外,看看随身源$ C ​​$ C,了解有关如何在Go包装一个C库为例code杂项/ CGO / GMP。

How does one interface a Go program with a C library?

I've been browsing Go's source code but I still didn't figured it out. If someone has already done so, could you share, please?

UPDATED: Thanks to @fserb, I am posting some documentation from the Go sources:

Cgo enables the creation of Go packages that call C code.

Usage: cgo [compiler options] file.go

The compiler options are passed through uninterpreted when invoking gcc to compile the C parts of the package.

The input file.go is a syntactically valid Go source file that imports the pseudo-package "C" and then refers to types such as C.size_t, variables such as C.stdout, or functions such as C.putchar.

If the import of "C" is immediately preceded by a comment, that comment is used as a header when compiling the C parts of the package. For example:

// #include <stdio.h>
// #include <errno.h>
import "C"

Cgo transforms the input file into four output files: two Go source files, a C file for 6c (or 8c or 5c), and a C file for gcc.

The standard package makefile rules in Make.pkg automate the process of using cgo. See $GOROOT/misc/cgo/stdio and $GOROOT/misc/cgo/gmp for examples.

Cgo does not yet work with gccgo.

解决方案

Check cgo. Also, take a look at misc/cgo/gmp on the Go source code for an example code on how to wrap a C library in Go.

这篇关于接口与围棋C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆