Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use swig with compiled dll and header file only

I have read some docs from SWIG documentation (related to c++ code), but can't figure out if it is possible to genereate Python extension module in case I have compiled dll (no source code provided) and header file with all functions declared in dll.
If someone has the same problem and solve it, could you provide some useful example?
Thanks in advance.

like image 656
tema Avatar asked May 06 '15 12:05

tema


People also ask

Does DLL include header files?

There's no such a thing like "include header files in a dll file". What you can do is: include header files in a source code file (i.e. *.

Can I use DLL without the header?

If you DO have appropriate . LIB file, and you have exact function prototype, you don't need header. Just declare the functions youself (possibly in your own custom header).

How do I create a swig interface file?

The most common format of a SWIG interface is as follows: %module mymodule %{ #include "myheader. h" %} // Now list ANSI C/C++ declarations int foo; int bar(int x); ... The module name is supplied using the special %module directive.

What is SWIG library?

The Simplified Wrapper and Interface Generator (SWIG) is an open-source software tool used to connect computer programs or libraries written in C or C++ with scripting languages such as Lua, Perl, PHP, Python, R, Ruby, Tcl, and other languages like C#, Java, JavaScript, Go, D, OCaml, Octave, Scilab and Scheme.


1 Answers

Yes, it is possible. SWIG only uses the headers to generate wrapper functions. Here's a simple SWIG file:

%module mymod
%{
#include "myheader.h"
%}

%include "myheader.h"

Then:

swig -python -c++ mymod.i

Then compile and link the generated code as a Python extension DLL. You will also need to link in the .lib for the wrapped DLL.

like image 178
Mark Tolonen Avatar answered Nov 14 '22 02:11

Mark Tolonen