当前位置:网站首页>SWIG tutorial "four" - package of go language
SWIG tutorial "four" - package of go language
2022-08-10 14:59:00 【Akure Studio】
以Go 封装为例
goThe language does not support direct invocationC或者C++语言,虽然通过cgo转接go可以实现对c的调用,However, there is no or no direct conversion between the various data types of the calling process,使用起来也不是很方便,而swigJust enough to fill this gap
而且只要是go 1.2之后的版本,可以通过go build直接使用swig生成的源码
虽然swig会尽量将C、C++封装成go代码,But due to the difference between the two languages,There will still be some changes in there,比如constTypes are only available externallyGet接口来实现,通过deferTo realize the management of object memory, etc.
为了能够实现go->c++->gocall of this form,Proxy mode must be used,The proxy mode must complete the following content in the directive file
First declare the use of proxy mode on the module
%module(directors="1") modulename
Specify the proxy on the class where the proxy needs to be set
%feature("director") FooBarAbstruct;
Import additional modules
%go_import("fmt", _ "unusedPackage", rp "renamed/package")
%insert(go_wrapper) %{
func foo() {
fmt.Println("Some string:", rp.GetString())
}
// Importing the same package twice is permitted,
// Go code will be generated with only the first instance of the import.
%go_import("fmt")
%insert(go_wrapper) %{
func bar() {
fmt.Println("Hello world!")
}
%}
使用说明
Swig 给出选项,And indicate the files that need to be encapsulated,The specified file can be encapsulated.
where filename is a SWIG interface file or a C/C++ header file
swig [ options ] filename
swig
Generate bindings between C / C++ code and various high level languages such as Javascript, Python, C#, and more.It uses special .i or .swg files to generate the bindings (C/C++ with SWIG directives, then outputs a C/C++ file that contains all of the wrapper code needed to build an extension module.
- Generate a binding between C++ and Python:
swig -c++ -python -o {{path/to/output_wrapper.cpp}} {{path/to/swig_file.i}}
- Generate a binding between C++ and Go:
swig -go -cgo -intgosize 64 -c++ {{path/to/swig_file.i}}
- Generate a binding between C and Java:
swig -java {{path/to/swig_file.i}}
- Generate a binding between C and Ruby and prefix the Ruby module with {{foo::bar::}}:
swig -ruby -prefix "{{foo::bar::}}" {{path/to/swig_file.i}}
边栏推荐
- Systemui status bar to add a new icon
- 中学数学建模书籍及相关的视频等(2022.08.09)
- 第五讲 测试技术与用例设计
- 司空见惯 - 股市狠狠下跌后,何時能反弹?
- 线上线下课程教学培训小程序开发制作功能介绍
- Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
- awk的简单使用
- 阿里五位MySQL封神大佬耗17个月总结出53章性能优化法则
- Based on Azuki Series: NFT Valuation Analysis Framework "DRIC"
- 【吴恩达来信】强化学习的发展!
猜你喜欢

MySQL - storage engine for databases

线上线下课程教学培训小程序开发制作功能介绍

第五讲 测试技术与用例设计

缺少比较器,运放来救场!(运放当做比较器电路记录)

How does IT Xiaobai learn PHP systematically

Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!

数学建模学习视频及资料集(2022.08.10)

awk的简单使用
![[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files](/img/ec/87566763daf7faa3769ee186f93ee0.jpg)
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files

WSL 提示音关闭
随机推荐
SWIG Tutorial "One"
XML基本学习
antd组件中a-modal设置固定高度,内容滚动显示
基于 Azuki 系列:NFT估值分析框架“DRIC”
程序员=加班??——掌握时间才能掌握人生
使用Uiautomator2进行APP自动化测试
Rich Dad Poor Dad Reading Notes
从洞察到决策,一文解读标签画像体系建设方法论
SWIG教程《一》
统信 UOS V20 专业版(1050update2)发布:文件共享、全局搜索等优化
Alibaba的秒杀系统—千亿级并发设计手册上线了
redhat替换yum源时redhat.repo无法删除或无法禁用的问题解决方法
机器学习总结(一)
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
缺少比较器,运放来救场!(运放当做比较器电路记录)
产品使用说明书小程序开发制作说明
epoll学习:思考一种高性能的服务器处理框架
Mini Program-Voice broadcast function
tensorflow安装踩坑总结
BCG库简介