GenericAlias
GenericAlias

Reputation: 445

SWIG: Can you make C++ usable in Python using exclusively the C++ header file using SWIG?

I was trying to learn how to use SWIG and was wondering if I was doing some extra steps that I didn't need to do. I currently have the files Dog.cpp, Dog.h, and Dog.i.I'm trying to wrap Dog.cpp for use in Python using SWIG. My interface file, Dog.i, looks as follows:

%module Dog
%{
#include "Dog.h"
%}

%include "Dog.h"

I currently create the python wrapper by executing the following steps on the command line:

swig -c++ -python Dog.i

g++ -fpic -c Dog.cpp

g++ -fpic -c Dog_wrap.cxx -I /usr/include/python2.7

g++ -shared Dog.o Dog_wrap.o -o _Dog.so

My question is, is there a way to create the python wrapper without referencing Dog.cpp at all? For example, if I didn't know where Dog.cpp was located, is there a way I could still get things working? Thank you!

Upvotes: 1

Views: 102

Answers (1)

R Sahu
R Sahu

Reputation: 206557

My question is, is there a way to create the python wrapper without referencing Dog.cpp at all?

You can do that only if you create two DLLs/shared libraries. One DLL/shared libaray could have the object code corresponding toe Dog.cpp while the second DLL/shared library could have the Python wrapper code.

If you want to create one DLL/shared library or an executable, then you have to link the object code from Dog.cpp with the object code from the Python wrapper.

There is a reason the Python wrapper code is named that way. It is just a wrapper to the code in Dog.cpp.

Upvotes: 1

Related Questions