# c-for-go [![Go Report Card](https://goreportcard.com/badge/github.com/xlab/c-for-go)](https://goreportcard.com/report/github.com/xlab/c-for-go)
_Automatic C-Go Bindings Generator for Go Programming Language_
This project allows to reuse existing C/C++ libraries in your Go applications, by automatically creating [c-go bindings](https://golang.org/cmd/cgo/) for a given set of C headers and the manifest file. We believe in component-based software engineering and think that reusing C/C++ code in Go applications could bring a huge boost to developer's productivity and system's performance. Read more about the motivation: [top reasons to use bindings](https://github.com/xlab/c-for-go/wiki/Top-5-reasons-to-use-bindings).
### Process overview
<p align="center">
<img align="center" src="docs/overview.png" height="400px" alt="c-for-go process overview" />
</p>
The only component required to produce a Go package that will wrap the source C/C++ code is the YAML manifest file that defines parsing, translation and generation rules. The manifest can have just a few lines, however in order to match Go's naming conventions and provide enough tips for type conversions it usually contains about 100 lines, which is still better than producing tens of thousands lines of Go code by hand.
The resulting bindings are as low-level as C code, i.e. it would require knowledge of memory management to carefully use the resulting code, however no more C code is needed to make things done. Eventually some functions can be replaced manually with pure-Go analogs. Also usually a high-level wrapper is created by hand, to introduce Object Oriented Design into API, manage inner state and memory, thus making things safe and lifting the mental overhead.
Full documentation is available at https://github.com/xlab/c-for-go/wiki
### Installation
```bash
$ go get github.com/xlab/c-for-go
```
A simple [Makefile template](https://github.com/xlab/c-for-go/wiki/Makefile-template).
### In action
* https://github.com/xlab/android-go ð
* https://github.com/vulkan-go/vulkan ð
* https://github.com/golang-ui/nuklear
* https://github.com/xlab/pocketsphinx-go
* https://github.com/xlab/libvpx-go
* https://github.com/xlab/portaudio-go
* https://github.com/xlab/portmidi
* https://github.com/xlab/alac-go
* https://github.com/xlab/vorbis-go
* https://github.com/xlab/opus-go
* https://github.com/xlab/libpd-go
* https://github.com/zenhotels/lmdb-go
* https://github.com/zenhotels/libpostal-go
* https://github.com/xlab/hamlib-go
* https://github.com/5k3105/nidaq
* https://github.com/SphereSoftware/pdf-go
* ...
* [Request yours](max@kc.vc)
### Credits
* [Jan Mercl](https://github.com/cznic) for his [cznic/cc](https://gitlab.com/cznic/cc) C99 compiler front end package.
### License
MIT
没有合适的资源?快使用搜索试试~ 我知道了~
用于 Go 编程语言的自动 C-Go 绑定生成器.zip
共36个文件
go:26个
txt:2个
png:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 79 浏览量
2024-12-03
04:17:30
上传
评论
收藏 288KB ZIP 举报
温馨提示
用于 Go 编程语言的自动 C-Go 绑定生成器c-for-go用于 Go 编程语言的自动 C-Go 绑定生成器该项目允许在您的 Go 应用程序中重用现有的 C/C++ 库,方法是自动为给定的一组 C 头文件和清单文件创建c-go 绑定。我们相信基于组件的软件工程,并认为在 Go 应用程序中重用 C/C++ 代码可以极大地提高开发人员的生产力和系统性能。阅读有关动机的更多信息使用绑定的首要原因。流程概述生成包装源 C/C++ 代码的 Go 包所需的唯一组件是定义解析、转换和生成规则的 YAML 清单文件。清单可能只有几行,但为了符合 Go 的命名约定并提供足够的类型转换提示,它通常包含大约 100 行,这仍然比手动生成数万行 Go 代码要好。生成的绑定与 C 代码一样低级,也就是说,需要内存管理知识才能谨慎使用生成的代码,但无需更多 C 代码即可完成操作。最终,一些函数可以用纯 Go 模拟函数手动替换。此外,通常还会手动创建高级包装器,将面向对象设计引入 API,管理内部状态和内存,从而使事情变得安全并减轻精神负担。完整文档可在https://github.c
资源推荐
资源详情
资源评论
收起资源包目录
用于 Go 编程语言的自动 C-Go 绑定生成器.zip (36个子文件)
go.mod 846B
标签.txt 2B
go.sum 6KB
process.go 7KB
LICENSE 1KB
docs
overview.png 274KB
sphere.png 32KB
资源内容.txt 1KB
parser
parser.go 6KB
translator
model_function.go 2KB
model_declaration.go 1KB
model_type.go 3KB
ast_walker_test.go 28KB
helpers.go 7KB
array_spec.go 916B
rules.go 4KB
ast_walker.go 13KB
model_enum.go 3KB
translator.go 27KB
type_mapping.go 5KB
model_struct_union.go 3KB
model_go_type.go 5KB
.gitignore 25B
generator
gen_declares.go 5KB
gen_bindings.go 36KB
gen_files.go 5KB
gen_struct_helpers.go 11KB
Makefile 84B
gen_const.go 6KB
gen_typedef.go 5KB
gen_callbacks.go 9KB
generator.go 12KB
gen_union.go 98B
gen_common.go 5KB
README.md 3KB
main.go 3KB
共 36 条
- 1
资源评论
赵闪闪168
- 粉丝: 1655
- 资源: 5391
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 无人机检测2-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- linux内核学习很好的书籍,建议初学者都去阅读一下
- abb上位机开发,远程启动与数据读取
- wt-js-debug v2.7.6
- 施工防护检测38-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- 基于Python实现的新浪微博用户数据爬虫源码(文档说明,支持HTTP请求与数据解析,多格式数据存储与自动化采集)
- 实现按层次遍历二叉树的C++代码
- 施工防护分类检测45-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- 基于DS18B20数字温度计设计
- 地震数据处理小软件vista5.5
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功