Type "help", "copyright", "credits" or "license" for more information. This method is done manually in when using the generated Python code. Swig is the abbreviation of Simplified Wrapper and Interface Generator, it can give script language such as python the ability to invoke C and C++ libraries. In a more customary Python manner the first argument to a class method is the class object itself. Using the library in python not might needs be so straightforward. After adding that link everthing works very nicely. This turned out to be caused by not including the stdc++ link file linking. I was getting ImportError: ImportError: undefined symbol: _ZTVN10_cxxabiv117_class_type_infoE errors in python when importing the library.
Gcc -shared example_wrap.o Word.o -o _example.so -lstdc++ You need to add the include directory to that the compilation can find "Python.h". G++ -fpic -c example.h example_wrap.cxx Word.cpp -I/usr/include/python2.7/ Note: The **-c++** help because it tells SWIG what language is being wrapped, I think it might be C be default. Unix cc compiler to Microsoft's cl compiler wrapper. The errors you get from this process may not seem simple. SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
SWIG can generate a enormous wrapper file that is almost unreadable and then you need to compile it. I found this part to be the most confusing and difficult. Note: to be able to use std::string properly you need to include the interface file for the class (std_string.i).This interface file includes both the header files for the methods and class(es) I want to be able to use in Python. * Put header files here or function declarations like below */
In the file you should include all of the methods/attributes/variables/header file you want to be exported. There are some global methods, some global variables and a class that uses a non C-like class std::string.Īn interface file is kind of like a header file but to be used specifically by swig. SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and Tcl. I am going to want to wrap far more complex data types and classes.
#Swig software wrapper generator#
Wrapper and Interface Generator 8), a software development tool. There is a short tutorial on this page which covers some of the basics, however this is not enough. Generation of the SWIGLAL interface uses SWIG (Simplified.
#Swig software wrapper code#
In order to be able to access the C++ code from Python (or other languages) I have wrapped some of the functionality using SWIG ( Simple Wrapper Interface Generator).