当前位置:网站首页>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}}
边栏推荐
- Boss raises salary!Look at my WPF Loading!!!
- tensorflow安装踩坑总结
- C#实现访问OPC UA服务器
- Alibaba的秒杀系统—千亿级并发设计手册上线了
- Go Context基本使用
- 自定义picker滚动选择器样式
- Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth
- redhat替换yum源时redhat.repo无法删除或无法禁用的问题解决方法
- Websocket realizes real-time change of chart content
- 丁香园
猜你喜欢
随机推荐
等保2.0一个中心三重防护指的是什么?如何理解?
强意识 压责任 安全培训筑牢生产屏障
Epoll learn to think: a high performance server processing framework
usb转rs485测试软件,usb转rs485「建议收藏」
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
中学数学建模书籍及相关的视频等(2022.08.09)
2022年中国软饮料市场洞察
@RequestBody的使用[通俗易懂]
Unfinished mathematics test paper ----- test paper generator (Qt includes source code)
PyTorch multi-machine multi-card training: DDP combat and skills
leetcode 739. Daily Temperatures 每日温度(中等)
MySQL Principle and Optimization: Update Optimization
符合信创要求的堡垒机有哪些?支持哪些系统?
【语义分割】DeepLab系列
【MindSpore易点通机器人-02】设计与技术选型
奢侈品鉴定机构小程序开发制作功能介绍
老板加薪!看我做的WPF Loading!!!
无线网络、HTTP缓存、IPv6
【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
fatal error C1083 无法打开包括文件'io.h' No such file