2 引言

2.1 SWIG 是什么?

SWIG is a software development tool that simplifies the task of interfacing different languages to C and C++ programs. In a nutshell, SWIG is a compiler that takes C/C++ declarations and creates the wrappers needed to access those declarations from other languages including Perl, Python, Tcl, Ruby, Guile, and Java. SWIG normally requires no modifications to existing code and can often be used to build a usable interface in only a few minutes. Possible applications of SWIG include:

  • Building interpreted interfaces to existing C programs.
  • Rapid prototyping and application development.
  • Interactive debugging.
  • Reengineering or refactoring of legacy software into scripting language components.
  • Making a graphical user interface (using Tk for example).
  • Testing of C libraries and programs (using scripts).
  • Building high performance C modules for scripting languages.
  • Making C programming more enjoyable (or tolerable depending on your point of view).
  • Impressing your friends.
  • Obtaining vast sums of research funding (although obviously not applicable to the author).

SWIG was originally designed to make it extremely easy for scientists and engineers to build extensible scientific software without having to get a degree in software engineering. Because of this, the use of SWIG tends to be somewhat informal and ad-hoc (e.g., SWIG does not require users to provide formal interface specifications as you would find in a dedicated IDL compiler). Although this style of development isn't appropriate for every project, it is particularly well suited to software development in the small; especially the research and development work that is commonly found in scientific and engineering projects. However, nowadays SWIG is known to be used in many large open source and commercial projects.

SWIG 是一款软件开发工具,它简化了将不同语言连接到 C 和 C++ 程序的任务。简而言之,SWIG 是一个编译器,它接受 C/C++ 声明并创建从其他语言(包括 Perl、Python、Tcl、Ruby、Guile 和 Java)访问这些声明所需的包装器。SWIG 通常不需要修改现有代码,并且可以在几分钟内构建可用的接口。SWIG 可能的应用包括:

  • 构建现有 C 程序的解释接口。
  • 快速原型设计和应用程序开发。
  • 交互式调试。
  • 将历史遗留软件重新设计或重构为脚本语言组件。
  • 制作图形用户(例如使用 Tk)。
  • 测试 C 代码库和程序(使用脚本)。
  • 为脚本语言构建高性能 C 模块。
  • 使 C 编程更愉快(或视你的情况而定)。
  • 给你的朋友留下深刻印象
  • 获得大量研究经费(虽然显然不适用于作者本人)。

SWIG 最初旨在使科学家和工程师能够非常轻松地构建可扩展的科学软件,而无需软件工程学位。因此,SWIG 的使用往往是非正式的和临时的(例如,SWIG 不要求用户提供正式的接口规范,就像你在专用的 IDL 编译器中找到的那样)。虽然这种开发方式并不适合每个项目,但它特别适合于小型软件开发,特别是科学和工程项目中常见的研究和开发工作。但是,如今已知 SWIG 可用于许多大型开源和商业项目。

2.2 为什么使用 SWIG?

As stated in the previous section, the primary purpose of SWIG is to simplify the task of integrating C/C++ with other programming languages. However, why would anyone want to do that? To answer that question, it is useful to list a few strengths of C/C++ programming:

  • Excellent support for writing programming libraries.
  • High performance (number crunching, data processing, graphics, etc.).
  • Systems programming and systems integration.
  • Large user community and software base.

Next, let's list a few problems with C/C++ programming

  • Writing a user interface is rather painful (i.e., consider programming with MFC, X11, GTK, or any number of other libraries).
  • Testing is time consuming (the compile/debug cycle).
  • Not easy to reconfigure or customize without recompilation.
  • Modularization can be tricky.
  • Security concerns (buffer overflows for instance).

To address these limitations, many programmers have arrived at the conclusion that it is much easier to use different programming languages for different tasks. For instance, writing a graphical user interface may be significantly easier in a scripting language like Python or Tcl (consider the reasons why millions of programmers have used languages like Visual Basic if you need more proof). An interactive interpreter might also serve as a useful debugging and testing tool. Other languages like Java might greatly simplify the task of writing distributed computing software. The key point is that different programming languages offer different strengths and weaknesses. Moreover, it is extremely unlikely that any programming is ever going to be perfect. Therefore, by combining languages together, you can utilize the best features of each language and greatly simplify certain aspects of software development.

From the standpoint of C/C++, a lot of people use SWIG because they want to break out of the traditional monolithic C programming model which usually results in programs that resemble this:

  • A collection of functions and variables that do something useful.
  • A main() program that starts everything.
  • A horrible collection of hacks that form some kind of user interface (but which no-one really wants to touch).

Instead of going down that route, incorporating C/C++ into a higher level language often results in a more modular design, less code, better flexibility, and increased programmer productivity.

SWIG tries to make the problem of C/C++ integration as painless as possible. This allows you to focus on the underlying C program and using the high-level language interface, but not the tedious and complex chore of making the two languages talk to each other. At the same time, SWIG recognizes that all applications are different. Therefore, it provides a wide variety of customization features that let you change almost every aspect of the language bindings. This is the main reason why SWIG has such a large user manual

SWIG 3 中文手册——2. 引言的更多相关文章

  1. SWIG 3 中文手册——1. 前言

    目录 1 前言 1.1 引言 1.2 SWIG 版本 1.3 SWIG 许可证 1.4 SWIG 资源 1.5 前提要求 1.6 本手册的组织构成 1.7 如何避免阅读手册 1.8 向后兼容 1.9 ...

  2. SWIG 3 中文手册——5. SWIG 基础知识

    目录 5 SWIG 基础知识 5.1 运行 SWIG 5.1.1 输入格式 5.1.2 SWIG 输出 5.1.3 注释 5.1.4 C 预处理器 5.1.5 SWIG 指令 5.1.6 解析限制 5 ...

  3. SWIG 3 中文手册——4. 脚本语言

    目录 4 脚本语言 4.1 两种语言的概览 4.2 脚本语言如何调用 C? 4.2.1 包装器函数 4.2.2 变量链接 4.2.3 常量 4.2.4 结构体与类 4.2.5 代理类 4.3 构建脚本 ...

  4. SWIG 3 中文手册——10. 参数处理

    目录 10 参数处理 10.1 typemaps.i 库 10.1.1 引言 10.1.2 输入参数 10.1.3 输出参数 10.1.4 输入 / 输出参数 10.1.5 使用不同的名称 10.2 ...

  5. SWIG 3 中文手册——6. SWIG 和 C++

    目录 6 SWIG 和 C++ 6.1 关于包装 C++ 6.2 方法 6.3 支持的 C++ 功能 6.4 命令行选项与编译 6.5.1 代理类的构造 6.5.2 代理类中的资源管理 6.5.3 语 ...

  6. SWIG 3 中文手册——3. Windows 上使用 SWIG

    目录 3 Windows 上使用 SWIG 后续章节 3 Windows 上使用 SWIG 暂时略过. 后续章节 <4. 脚本语言>

  7. SWIG 3 中文手册——9. SWIG 库

    目录 9 SWIG 库 9.1 %include 指令与库搜索路径 9.2 C 数组与指针 9.2.1 cpointer.i 9.2.2 carrays.i 9.2.3 cmalloc.i 9.2.4 ...

  8. NVelocity介绍,NVelocity中文手册文档及实例下载

    NVelocity是什么velocity英音:[vi'lɔsiti]美音:[və'lɑsətɪ]近在做一个项目,客户要求有网站模板功能,能够自主编辑网站的风格,因为这个系统是为政府部门做子站系统,举个 ...

  9. (转)Sqoop中文手册

    Sqoop中文手册 1.     概述 本文档主要对SQOOP的使用进行了说明,参考内容主要来自于Cloudera SQOOP的官方文档.为了用中文更清楚明白地描述各参数的使用含义,本文档几乎所有参数 ...

随机推荐

  1. 玩透二叉树(Binary-Tree)及前序(先序)、中序、后序【递归和非递归】遍历

    基础预热: 结点的度(Degree):结点的子树个数:树的度:树的所有结点中最大的度数:叶结点(Leaf):度为0的结点:父结点(Parent):有子树的结点是其子树的根节点的父结点:子结点/孩子结点 ...

  2. php服务端搜索,功能改进

    php中 ,一直以来,服务端搜索,我都是写一堆条件判断,搜索条件少时还好,条件一多,就显的代码有点丑陋了: 看着非常不舒服.今天在园子里看到一篇文章(http://www.cnblogs.com/xq ...

  3. 极速体验docker容器健康

    本文目是体验docker容器的健康检查功能,以体验为主不涉及开发,与开发相关的内容会在后面的文章细说. 关于容器健康检查 考虑这样的情况:docker环境中,springboot应用的容器还在,但已无 ...

  4. 搜索引擎elasticsearch监控利器cat命令

    目录 一.Cat通用参数 二.cat命令 三.示例 查询aurajike索引下的总文档数和有效文档数 查询aurajike各分片的调度情况 一.Cat通用参数 参数名 指令示例 功能 Verbose ...

  5. html、css/bootStrap、js/Jquery、ajax与json数据交互总结

    设计个个人网站,利用CSS.JavaScript.HTML5.jQuery库和AJAX等 实现网站各功能模块,下面介绍我设计的网站各大功能模块:  个人简历模块: 包涵个人基本信息(利用CSS的flo ...

  6. Android源码分析(十一)-----Android源码中如何引用aar文件

    一:aar文件如何引用 系统Settings中引用bidehelper-1.1.12.aar 文件为例 源码地址:packages/apps/Settings/Android.mk LOCAL_PAT ...

  7. youtube-dll工具使用,很好用!!

    最近喜欢上youtube-dll这个插件,下载东西真的很好用,墙裂推荐,github地址如下 https://github.com/ytdl-org/youtube-dl 安装 1.Linux 1.1 ...

  8. 《linux就该这么学》课堂笔记19 iSCSI、MariaDB、无人值守安装

    1.iSCSI技术介绍 硬盘是计算机硬件设备中重要的组成部分之一,硬盘存储设备读写速度的快慢也会对服务器的整体性能造成影响. 为了进一步提升硬盘存储设备的读写速度和性能,人们一直在努力改进物理硬盘设备 ...

  9. MySol序

    1.mysql是基于C/S端的服务器软件 mysql服务端: server端开启,对文件的增删改查 , musql客户端::连接S端, 发送指令 isnert into t1 values(1); 2 ...

  10. 谷歌学术出现We're sorry解决办法

    出现这个的原因应该是同ip段的或者就是这个ip曾经是个google的黑名单ip,因为恶意爬取谷歌学术了.解决办法就是申请Hurricane Electric Free IPv6 Tunnel Brok ...