SWIG:SWIG的简介、安装、使用方法之详细攻略

简介: SWIG:SWIG的简介、安装、使用方法之详细攻略


目录

SWIG的简介

SWIG的安装

SWIG的使用方法


 

 

 

 

SWIG的简介

       SWIG是一种软件开发工具,它将C和C++编写的程序与各种高级编程语言连接起来。SWIG用于不同类型的目标语言,包括常见的脚本语言,如Javascript、Perl、PHP、Python、Tcl和Ruby。支持的语言列表还包括非脚本语言,如C#,D,Go language,Java,包括Android,Lua,OCaml,Octave,Scilab和R。还支持几种解释和编译的Scheme实现(Guile,MzScheme/Racket)。

         SWIG最常用于创建高级解释或编译的编程环境、用户界面,以及作为测试和原型化C/C++软件的工具。SWIG通常用于解析C/C++接口,并生成用于上述目标语言调用C/C++代码所需的“胶粘代码”。SWIG还可以XML格式导出解析树。SWIG是自由软件,SWIG生成的代码与商业和非商业项目都兼容。

SWIG官网:http://www.swig.org/

 

SWIG的安装

下载地址:https://sourceforge.net/projects/swig/files/swig/swig-4.0.1/swig-4.0.1.tar.gz/download?use_mirror=nchc

注:切记,下载的时候要选择对应的系统,比如博主选择的是Win10系统对应的swigwin-4.0.1压缩包。

安装教程:

 

 

 

SWIG的使用方法

1. C:\Users>swig -help
2. Supported Target Language Options
3.      -csharp         - Generate C# wrappers
4.      -d              - Generate D wrappers
5.      -go             - Generate Go wrappers
6.      -guile          - Generate Guile wrappers
7.      -java           - Generate Java wrappers
8.      -javascript     - Generate Javascript wrappers
9.      -lua            - Generate Lua wrappers
10.      -octave         - Generate Octave wrappers
11.      -perl5          - Generate Perl 5 wrappers
12.      -php7           - Generate PHP 7 wrappers
13.      -python         - Generate Python wrappers
14.      -r              - Generate R (aka GNU S) wrappers
15.      -ruby           - Generate Ruby wrappers
16.      -scilab         - Generate Scilab wrappers
17.      -tcl8           - Generate Tcl 8 wrappers
18.      -xml            - Generate XML wrappers
19. 
20. Experimental Target Language Options
21.      -mzscheme       - Generate MzScheme/Racket wrappers
22.      -ocaml          - Generate OCaml wrappers
23. 
24. General Options
25.      -addextern      - Add extra extern declarations
26.      -c++            - Enable C++ processing
27.      -co <file>      - Check <file> out of the SWIG library
28.      -copyctor       - Automatically generate copy constructors wherever possible
29.      -cpperraswarn   - Treat the preprocessor #error statement as #warning (default)
30.      -cppext <ext>   - Change file extension of generated C++ files to <ext>
31.                        (default is cxx)
32.      -copyright      - Display copyright notices
33.      -debug-classes  - Display information about the classes found in the interface
34.      -debug-module <n>- Display module parse tree at stages 1-4, <n> is a csv list of stages
35.      -debug-symtabs  - Display symbol tables information
36.      -debug-symbols  - Display target language symbols in the symbol tables
37.      -debug-csymbols - Display C symbols in the symbol tables
38.      -debug-lsymbols - Display target language layer symbols
39.      -debug-tags     - Display information about the tags found in the interface
40.      -debug-template - Display information for debugging templates
41.      -debug-top <n>  - Display entire parse tree at stages 1-4, <n> is a csv list of stages
42.      -debug-typedef  - Display information about the types and typedefs in the interface
43.      -debug-typemap  - Display typemap debugging information
44.      -debug-tmsearch - Display typemap search debugging information
45.      -debug-tmused   - Display typemaps used debugging information
46.      -directors      - Turn on director mode for all the classes, mainly for testing
47.      -dirprot        - Turn on wrapping of protected members for director classes (default)
48.      -D<symbol>      - Define a symbol <symbol> (for conditional compilation)
49.      -E              - Preprocess only, does not generate wrapper code
50.      -external-runtime [file] - Export the SWIG runtime stack
51.      -fakeversion <v>- Make SWIG fake the program version number to <v>
52.      -fcompact       - Compile in compact mode
53.      -features <list>- Set global features, where <list> is a comma separated list of
54.                        features, eg -features directors,autodoc=1
55.                        If no explicit value is given to the feature, a default of 1 is used
56.      -fastdispatch   - Enable fast dispatch mode to produce faster overload dispatcher code
57.      -Fmicrosoft     - Display error/warning messages in Microsoft format
58.      -Fstandard      - Display error/warning messages in commonly used format
59.      -fvirtual       - Compile in virtual elimination mode
60.      -help           - Display help
61.      -I-             - Don't search the current directory
62.      -I<dir>         - Look for SWIG files in directory <dir>
63.      -ignoremissing  - Ignore missing include files
64.      -importall      - Follow all #include statements as imports
65.      -includeall     - Follow all #include statements
66.      -l<ifile>       - Include SWIG library file <ifile>
67.      -macroerrors    - Report errors inside macros
68.      -makedefault    - Create default constructors/destructors (the default)
69.      -M              - List all dependencies
70.      -MD             - Is equivalent to `-M -MF <file>', except `-E' is not implied
71.      -MF <file>      - Generate dependencies into <file> and continue generating wrappers
72.      -MM             - List dependencies, but omit files in SWIG library
73.      -MMD            - Like `-MD', but omit files in SWIG library
74.      -module <name>  - Set module name to <name>
75.      -MP             - Generate phony targets for all dependencies
76.      -MT <target>    - Set the target of the rule emitted by dependency generation
77.      -nocontract     - Turn off contract checking
78.      -nocpperraswarn - Do not treat the preprocessor #error statement as #warning
79.      -nodefault      - Do not generate default constructors nor default destructors
80.      -nodefaultctor  - Do not generate implicit default constructors
81.      -nodefaultdtor  - Do not generate implicit default destructors
82.      -nodirprot      - Do not wrap director protected members
83.      -noexcept       - Do not wrap exception specifiers
84.      -nofastdispatch - Disable fast dispatch mode (default)
85.      -nopreprocess   - Skip the preprocessor step
86.      -notemplatereduce - Disable reduction of the typedefs in templates
87.      -O              - Enable the optimization options:
88.                         -fastdispatch -fvirtual
89.      -o <outfile>    - Set name of C/C++ output file to <outfile>
90.      -oh <headfile>  - Set name of C++ output header file for directors to <headfile>
91.      -outcurrentdir  - Set default output dir to current dir instead of input file's path
92.      -outdir <dir>   - Set language specific files output directory to <dir>
93.      -pcreversion    - Display PCRE version information
94.      -small          - Compile in virtual elimination and compact mode
95.      -swiglib        - Report location of SWIG library and exit
96.      -templatereduce - Reduce all the typedefs in templates
97.      -v              - Run in verbose mode
98.      -version        - Display SWIG version number
99.      -Wall           - Remove all warning suppression, also implies -Wextra
100.      -Wallkw         - Enable keyword warnings for all the supported languages
101.      -Werror         - Treat warnings as errors
102.      -Wextra         - Adds the following additional warnings: 202,309,403,405,512,321,322
103.      -w<list>        - Suppress/add warning messages, eg -w401,+321 - see Warnings.html
104.      -xmlout <file>  - Write XML version of the parse tree to <file> after normal processing
105. 
106. Options can also be defined using the SWIG_FEATURES environment variable, for example:
107. 
108.   $ SWIG_FEATURES="-Wall"
109.   $ export SWIG_FEATURES
110.   $ swig -python interface.i
111. 
112. is equivalent to:
113. 
114.   $ swig -Wall -python interface.i
115. 
116. Arguments may also be passed in a file, separated by whitespace. For example:
117. 
118.   $ echo "-Wall -python interface.i" > args.txt
119.   $ swig @args.txt
120. 
121. 
122. Note: 'swig -<lang> -help' displays options for a specific target language.

 


相关文章
|
人工智能 机器人 C++
【C++/Python】Windows用Swig实现C++调用Python(史上最简单详细,80岁看了都会操作)
【C++/Python】Windows用Swig实现C++调用Python(史上最简单详细,80岁看了都会操作)
|
Web App开发 Ubuntu 安全
【已解决】ubuntu 16.04安装最新版本google chrome出错, 旧版本chrome浏览器安装流程
【已解决】ubuntu 16.04安装最新版本google chrome出错, 旧版本chrome浏览器安装流程
3100 2
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
40005 114
|
Rust 算法 Linux
Rocky Linux 10.1 发布 - RHEL 100% 1:1 兼容免费发行版
Rocky Linux 10.1 发布 - RHEL 100% 1:1 兼容免费发行版
880 0
Rocky Linux 10.1 发布 - RHEL 100% 1:1 兼容免费发行版
|
JavaScript C++
基于QtQuick的QCustomPlot实现
本文介绍了如何在QtQuick中实现基于QCustomPlot的图表绘制,包括效果图展示、C++和QML方面的实现代码、注意事项以及应用场景。作者提供了源码下载链接,方便读者学习和使用QCustomPlot进行QtQuick应用程序中的图表绘制。
915 4
基于QtQuick的QCustomPlot实现
|
JSON 数据挖掘 API
京东商品视频 API 接口系列(京东 API)
京东商品视频API用于获取商品视频的URL、时长、分辨率等信息,适用于电商平台开发、数据分析、商品推荐优化及竞品分析。需安装`requests`库并使用Python内置`json`库解析数据。请求时需提供`productId`等参数,返回JSON格式数据。示例代码展示了如何通过签名验证和参数构建进行API调用。
|
存储 安全 Java
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
在一次意外中,作者因三年前将测试代码遗忘在GitHub上而遭遇了代码被他人fork的问题。为解决这一危机,作者详细介绍了如何通过GitHub的DMCA下架通知流程安全删除敏感代码,包括处理私人信息和商标侵权的具体步骤。本文不仅提供了实用的操作指南,还强调了及时响应的重要性,帮助读者避免类似风险
1276 1
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
|
人工智能
[AI 快手 LivePortrait] 引领高效肖像动画新时代
快手推出了 LivePortrait,具备拼接与重定向控制的高效肖像动画,下载代码,准备环境,下载预训练权重并开始推理。
[AI 快手 LivePortrait] 引领高效肖像动画新时代
|
前端开发 JavaScript
node反向代理,解决跨域(http-proxy-middleware)
使用node.js和http-proxy-middleware库实现反向代理,解决跨域问题,允许前端请求通过代理访问不同端口的服务。
1103 3