当前位置:网站首页>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}}
边栏推荐
- JS入门到精通完整版
- 1004 (tree array + offline operation + discretization)
- epoll学习:思考一种高性能的服务器处理框架
- High-paid programmers & interview questions series 135 How do you understand distributed?Do you know CAP theory?
- 【语义分割】DeepLab系列
- Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
- 1W字详解线程本地存储 ThreadLocal
- 力扣解法汇总640-求解方程
- 解读STEAM教育中的表现性评价
- tensorflow安装踩坑总结
猜你喜欢
Azure IoT Partner Technology Empowerment Workshop: IoT Dev Hack
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
正则表达式(包含各种括号,echo,正则三剑客以及各种正则工具)
字节终面:CPU 是如何读写内存的?
从洞察到决策,一文解读标签画像体系建设方法论
强意识 压责任 安全培训筑牢生产屏障
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
【MindSpore易点通机器人-02】设计与技术选型
IT小白怎么系统的php学习
符合信创要求的堡垒机有哪些?支持哪些系统?
随机推荐
fatal error C1083 无法打开包括文件'io.h' No such file
Steam教育在新时代中综合学习论
使用mysq语句操作数据库
List集合
Redis -- Nosql
力扣解法汇总640-求解方程
字节终面:CPU 是如何读写内存的?
微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
程序员=加班??——掌握时间才能掌握人生
《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
PEST 分析法
Flask框架——基于Celery的后台任务
中学数学建模书籍及相关的视频等(2022.08.09)
Understanding_Data_Types_in_Go
usb转rs485测试软件,usb转rs485「建议收藏」
电脑重装系统提示activex部件不能创建对象如何解决
Basic learning of XML
微信小程序,自定义输入框与导航胶囊对其
MySQL advanced (thirty-three) MySQL data table adding fields
TestLink导出用例转换工具