## SWIG

SWIG is stand along software development tool. It connects code programmed in C and C++ with many high-level programming languages including python. SWIG is used to parse C/C++ interfaces and generate the ‘glue code’ required for the above target languages to call into the C/C++ code.

The idea of SWIG is to create a dynamic python library module, which calls the SDK DLL. The structure is shown below.

The SWIG compiles the DLL and H files under the instruction of the .i file (SWIG configuring file). The SWIG project generates the Python Dynamic Library file (pyd). This pyd file can be imported to python.

## A Basic But Not Simple Example

### 1. Make a little DLL project.

In the repo, this little DLL project is xiaoAdd. There is a class AddTest. This class has only one useful member function add.

AddTest.h

/* AddTest.h */
#pragma once

{
public:
};


AddTest.cpp

/* AddTest.cpp */

{
}

{
}

{
return a+b;
}


Compile this project and get the results.

xiaoAdd.dll


### 2. Make a Python dynamic module

In the github repo, this module is xiaoA

/* AddTest.h */
#pragma once

{
public:
};


/* xiaoAddModule.i */

%{
/* Put header files here or function declarations like below */
%}

%include <windows.i>


#### 2. Build the project (Reference) including

xiaoAddModule_wrap.cxx


#### 3. Get the results

_xiaoAddModule.exp


#### 4. Write the Python script within the folder where above results are located.

test.py

# test.py