链接脚本语言和C/C++之间的最好的工具:SWIG
2012-07-01 00:22
274 查看
http://www.swig.org/translations/chinese/exec.html
SWIG是一个能将C或者C++编写的程序与其它各种高级语言如Perl, Python, Ruby, 和 Tcl进行联接的开发工具。其原理是从C/C++头文件中找到申明并利用他们生成脚本语言访问C/C++代码所必须的封装代码。SWIG具有高度可自定义的特点,它能帮助你生成适合你的应用程序的封装包。
John Ousterhout (Tcl的创造者) 写了一篇文章 描述SWIG对脚本语言的好处. SWIG能相当容易的将脚本语言和C/C++代码连接起了。
SWIG 主要用在以下几个方面:
编译更强大的C/C++程序.Using SWIG, you can replace the main() function of a C program with a scripting interpreter from which you can control the application. This adds quite a lot of flexibility and makes the program "programmable." That is, the
scripting interface allows users and developers to easily modifiy the behavior of the program without having to modify low-level C/C++ code. The benefits of this are numerous. In fact think of all of the large software packages that you use every day---nearly
all of them include special a macro language, configuration language, or even a scripting engine that allows users to make customizations.
快速构造原型和调试. SWIG allows C/C++ programs to be placed in a scripting environment that can be used for testing and debugging. For example, you might test a library with a collection of scripts or use the scripting interpreter as an interactive
debugger. Since SWIG requires no modifications to the underlying C/C++ code, it can be used even if the final product does not rely upon scripting.
系统集成. Scripting languages work fairly well for controlling and gluing loosely-coupled software components together. With SWIG, different C/C++ programs can be turned into scripting language extension modules. These modules can then be combined
together to create new and interesting applications.
架设脚本语言的扩展模块. SWIG can be used to turn common C/C++ libraries into components for use in popular scripting languages. Of course, you will still want to make sure that no-one else has already created a module before doing this.
SWIG is sometimes compared to interface definition language (IDL) compilers such as those you find with systems such as CORBA and COM. Although there are a few similarities, the whole point of SWIG is to make
it so you don't have to add an extra layer of IDL specifications to your application. If anything, it's much more of a rapid application development and prototyping tool. Specifically:
ANSI C/C++ syntax. SWIG parses ANSI C++ that has been extended with a number of special directives. As a result, interfaces are usually built by grabbing a header file and tweaking it a little bit. This particular approach is especially
useful when the underlying C/C++ program undergoes frequent modification.
SWIG is not a stub generator. SWIG produces code that you simply compile and run. You don't have to fill in any stubs or write special client/server code as you do with RPC-like systems.
SWIG does not define a protocol nor is it a component framework. SWIG does not define mechanisms or enforce rules regarding the way in which software components are supposed to interact with each other. Nor is it a specialized runtime library
or alternative scripting language API. SWIG is merely a code generator that provides the glue necessary to hook C/C++ to other languages.
Designed to work with existing C/C++ code. SWIG requires little, if any, modifications to existing code. For the most part, it encourages you to keep a clean separation between C/C++ and its scripting interface.
Extensibility. SWIG provides a variety of customization options that allow you to blow your whole leg off if that's what you want to do. SWIG is not here to enforce programming morality.
Finally, it is worth noting that even though SWIG is occasionally compared to other more specialized scripting language extension building tools (e.g., Perl XS, Python bgen, etc.), its primary audience is C/C++
programmers who want to add a scripting language component to their applications. Because of this, SWIG tends to have a slightly different focus than tools designed to build small modules for widespread use in a scripting language distribution. applications.
A number of papers and tutorials describing SWIG are available. You can also view a simple tutorial to
see an example of SWIG in action, or check out how other people are using SWIG in their projects.
SWIG has been freely available in various forms since February, 1996 and a large number of developers have made contributions. Today, SWIG remains an all-volunteer effort. Approximately 875 people subscribe to the swigmailing
list and a public SVN repository is available at SourceForge. Versions of SWIG can now be found in most Linux distributions (however, you'll almost certainly want to get the latest version here).
SWIG是一个能将C或者C++编写的程序与其它各种高级语言如Perl, Python, Ruby, 和 Tcl进行联接的开发工具。其原理是从C/C++头文件中找到申明并利用他们生成脚本语言访问C/C++代码所必须的封装代码。SWIG具有高度可自定义的特点,它能帮助你生成适合你的应用程序的封装包。
John Ousterhout (Tcl的创造者) 写了一篇文章 描述SWIG对脚本语言的好处. SWIG能相当容易的将脚本语言和C/C++代码连接起了。
SWIG 主要用在以下几个方面:
编译更强大的C/C++程序.Using SWIG, you can replace the main() function of a C program with a scripting interpreter from which you can control the application. This adds quite a lot of flexibility and makes the program "programmable." That is, the
scripting interface allows users and developers to easily modifiy the behavior of the program without having to modify low-level C/C++ code. The benefits of this are numerous. In fact think of all of the large software packages that you use every day---nearly
all of them include special a macro language, configuration language, or even a scripting engine that allows users to make customizations.
快速构造原型和调试. SWIG allows C/C++ programs to be placed in a scripting environment that can be used for testing and debugging. For example, you might test a library with a collection of scripts or use the scripting interpreter as an interactive
debugger. Since SWIG requires no modifications to the underlying C/C++ code, it can be used even if the final product does not rely upon scripting.
系统集成. Scripting languages work fairly well for controlling and gluing loosely-coupled software components together. With SWIG, different C/C++ programs can be turned into scripting language extension modules. These modules can then be combined
together to create new and interesting applications.
架设脚本语言的扩展模块. SWIG can be used to turn common C/C++ libraries into components for use in popular scripting languages. Of course, you will still want to make sure that no-one else has already created a module before doing this.
SWIG is sometimes compared to interface definition language (IDL) compilers such as those you find with systems such as CORBA and COM. Although there are a few similarities, the whole point of SWIG is to make
it so you don't have to add an extra layer of IDL specifications to your application. If anything, it's much more of a rapid application development and prototyping tool. Specifically:
ANSI C/C++ syntax. SWIG parses ANSI C++ that has been extended with a number of special directives. As a result, interfaces are usually built by grabbing a header file and tweaking it a little bit. This particular approach is especially
useful when the underlying C/C++ program undergoes frequent modification.
SWIG is not a stub generator. SWIG produces code that you simply compile and run. You don't have to fill in any stubs or write special client/server code as you do with RPC-like systems.
SWIG does not define a protocol nor is it a component framework. SWIG does not define mechanisms or enforce rules regarding the way in which software components are supposed to interact with each other. Nor is it a specialized runtime library
or alternative scripting language API. SWIG is merely a code generator that provides the glue necessary to hook C/C++ to other languages.
Designed to work with existing C/C++ code. SWIG requires little, if any, modifications to existing code. For the most part, it encourages you to keep a clean separation between C/C++ and its scripting interface.
Extensibility. SWIG provides a variety of customization options that allow you to blow your whole leg off if that's what you want to do. SWIG is not here to enforce programming morality.
Finally, it is worth noting that even though SWIG is occasionally compared to other more specialized scripting language extension building tools (e.g., Perl XS, Python bgen, etc.), its primary audience is C/C++
programmers who want to add a scripting language component to their applications. Because of this, SWIG tends to have a slightly different focus than tools designed to build small modules for widespread use in a scripting language distribution. applications.
A number of papers and tutorials describing SWIG are available. You can also view a simple tutorial to
see an example of SWIG in action, or check out how other people are using SWIG in their projects.
SWIG has been freely available in various forms since February, 1996 and a large number of developers have made contributions. Today, SWIG remains an all-volunteer effort. Approximately 875 people subscribe to the swigmailing
list and a public SVN repository is available at SourceForge. Versions of SWIG can now be found in most Linux distributions (however, you'll almost certainly want to get the latest version here).
相关文章推荐
- 使用swig工具为go语言与c++进行交互
- 我使用过的Linux命令之swig - 把C/C++的代码嵌入Java等语言的开发工具
- 我使用过的Linux命令之swig - 把C/C++的代码嵌入Java等语言的开发工具
- 动态语言、脚本语言和解释型语言之间有什么区别和联系
- 【cocos2d-x从c++到js】20:脚本语言风格的JS代码 推荐
- Linux下C/C++语言的调试 gdb工具 笔记
- 链接脚本在编程中的高级运用之二——运行时库和C++特性支持
- 使用SWIG实现C/C++与其他语言间的互相调用 zz
- 如何在Linux下用C/C++语言操作数据库sqlite3(很不错!设计编译链接等很多问题!)
- 编程语言与脚本语言之间的区别
- JNI学习笔记(二)JNI中的java语言与本地C/C++语言之间的映射(附例子)
- Android上的C/C++语言开发工具--simpleC开源
- 【COCOS2DX-LUA 脚本开发之十一】C/C++与Lua之间进行数据函数交互以及解决“PANIC: unprotected error in call to Lua API (转)
- SWIG实现C/C++与其他语言间的互相调用-----
- 通过Swig使C#可以链接C++编译的dll[勘误和修改]
- 脚本语言lua笔记(6)Lua调用c++自定义函数
- JNI学习笔记(二)JNI中的java语言与本地C/C++语言之间的映射(附例子)
- c++调用脚本语言
- 【脚本语言系列】关于Python测试工具mock, 你需要知道的事
- 脚本语言和.net方法之间的Excel导出间的秘籍(Mondify By LiFuyun)---续前面一篇文章