| SWIG - Way to link High level Programming languages and C/C++ modules |
| Written by khushboo diwakar | ||||
SWIG(Simplified Wrapper and Interface Generator) is a software development tool , an interface compiler that connects programs written in C and C++ with a variety of scripting languages such as Perl, Python, Ruby, and Tcl and also non-scripting languages such as C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Lua, Modula-3, OCAML and R. . "Scripts" are often treated as distinct from programs which execute independently from any other application. Many times we need to link C/C++ modules or small functions with a different language for our projects There are two main purposes of embedding a scripting language into an existing C/C++ program:
Its working is as follows
In addition, SWIG provides a variety of customization features that let us tailor the wrapping process to suit our application. SWIG may be freely used, distributed, and modified for commercial and non-commercial use.
SWIG is used in a number of ways: Building more powerful C/C++ programs. Using SWIG, we can replace the main() function of a C program with a scripting interpreter from which we 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. Rapid prototyping and debugging. 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. Systems integration. 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. Construction of scripting language extension modules. 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.
Well I got a very good example explaining the use of SWIG on this site http://www.swig.org/tutorial.html. Nothing can explain better than this.
Let's say we have modules in a file 'example.c'
/* File : example.c */
/* example.i */
$ swig -java example.i This is an example facilitating the linking of a java module with C/C++. For other high level languages refer http://www.swig.org/tutorial.html. SWIG 1.3.33 is the latest development release. Windows users should download swigwin-1.3.33 which includes a prebuilt executable. The release is available for download on Sourceforge at http://prdownloads.sourceforge.net/swig/swig-1.3.33.tar.gz A Windows version should also be available at http://prdownloads.sourceforge.net/swig/swigwin-1.3.33.zip Quote this article on your site
Only registered users can write comments. Powered by AkoComment Tweaked Special Edition v.1.4.6 |
||||
| < Prev |
|---|
Article Categories
| Web Development |
| Software Development |
| Programming Basics |
| Hardware |
| Operating Systems |
| Graphics |
| Miscellaneous |
| Submit Article / Tutorial |

Be first to comment this article