当前位置:网站首页>The language of CGO
The language of CGO
2022-08-05 20:53:00 【rainy day on the sun】
Click the link to view my personal blog, the article is more complete and detailed
Code on the shoulders of giants
C/c++, as the big brother, has accumulated a lot of excellent libraries.The Go language provides CGO tools to support C language function calls, and can also export the C dynamic library from the Go language to other languages.
How the Go language exports the C language dynamic library
CGO generally has three forms when using C/C++ resources: directly using source code; linking static library; linking dynamic library
Compile and link parameters
This is just a brief introduction, if you are interested, you can study it in depth~
1. Call the C language library
Take the classic hello world as an example
package main//#include import "C"func main() {C.puts(C.CString("Hello, World\n"))}2. Embed C language functions
package main/* #include void printint(int v) { printf("printint: %d\n", v); } */ import "C"func main() {v := 42C.printint(C.int(v))}package main/* #include static int div(int a, int b) { if (b==0) { errno = EINVAL; return 0; } return a/b;} */ import "C"import "fmt"func main() {v0, err0 := C.div(2,span> 1)fmt.Println(v0, err0)v1, err1 := C.div(2,span> 0)fmt.Println(v1, err1)}边栏推荐
- Aurora push custom sound stepping record (continuous update)
- 【StoneDB子查询优化】subquery子查询-内存拷贝分析及优化
- 3D U-Net: Learning Dense Volumetric Segmentation from Sparse Annotation
- Rust学习笔记:1.2 两个典例及常用命令
- 【kitti】terminate called after throwing an instance of ‘YAML::BadFile‘
- JS高阶(二)Symbol
- day15--Using postman to upload and download files
- SwiftUI case: custom loading animation
- Codeforces: d. Chip Move "dp + reverse thinking to consider"
- Win10 开机系统蓝屏代码0xc0000098,ntfs.sys损坏或丢失
猜你喜欢

C#NET6基于MailKit 进行邮件发送通知

codeforces: B. Maximum Xor Secondary【Monotone Stack】

【广告电商】全球排行榜前十的广告投放有哪些公司?

国产手机羡慕,中国年轻人追捧iPhone,推动苹果成最赚钱科技企业

day15--Using postman to upload and download files

数组的使用

Pytest Learning - The Best Way to Use Fixture

PID 控制理论

据称AMD Ryzen 9 7900X'Zen 4'CPU将提供比Zen 3多50%的缓存带宽

App测试时常用的adb命令你都掌握了哪些呢?
随机推荐
89.(cesium之家)cesium聚合图(自定义图片)
Notes of a grandfather who loves watching square dancing----strip command
Shell案例: jumpserver跳板机
体验golang1.18泛型
如何使用Solidity和Hardhat构建你自己的NFT以及NFT交易市场
App测试时常用的adb命令你都掌握了哪些呢?
【opencv图像处理】-- 6.图像轮廓(面积周长)、多边形逼近、外接矩形、查找/绘制轮廓
素数判断
TypeError:List indices must be integers or slices , not str
时间处理工具
codeforces:D. Chip Move【dp + 逆向思维考虑】
Rust学习笔记:2.1-2.3 猜数游戏
Rust学习笔记:3.1 变量与可变性
SwiftUI案例:Lottie载入动画
【StoneDB子查询优化】subquery子查询-内存拷贝分析及优化
弘泰俱乐部郭迎春、王志龙慈善暖人心活动
自动化网络配置
day15--Using postman to upload and download files
day15--使用postman进行文件的上传与下载
【视频】复杂网络分析CNA简介与R语言对婚礼数据聚类(社区检测)和可视化|数据分享