I am in the process of learning how to use SWIG on Windows.
The following is my c++ code:
/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area(void) {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area(void) {
return width*width;
}
double Square::perimeter(void) {
return 4*width;
}
This is my header file:
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
};
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
};
This is my interface file:
/* File : example.i */
%module example
%{
#include "example.h"
%}
%include "example.h"
I have managed to wrap my c++ code with the following command in Cygwin using SWIG:
$swig -c++ -python -o example_wrap.cpp example.i
My question is, how do I create a DLL from this point forward using the generated code (example_wrap.cpp)? Any ideas?
I tried creating a DLL with Visual Studio C++ 2010 but I get the build error:
LINK : fatal error LNK1104: cannot open file 'python27_d.lib
I'm fairly new to using SWIG so any help would be greatly appreciated.
Thanks!
You can try adding "python27_d.lib" (without quotes) to ignored libs:
Configuration Properties -> Linker -> Input -> Ignore Specific Library
I resolved the missing python27_d.lib by doing the following:
define Py_DEBUG