Questions tagged [swig]

SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and Tcl.

SWIG is typically used to parse C/C++ interfaces and generate the 'glue code' required for the target language to call into the C/C++ code. SWIG can also export its parse tree in the form of XML and Lisp s-expressions. SWIG is free software and the code that SWIG generates is compatible with both commercial and non-commercial projects.

For information about the features of SWIG and the supported languages see: http://www.swig.org/compare.html

One of many projects using SWIG to generate libraries for the above languages is Subversion. Other projects listed here.

Documentation:

3063 questions
27
votes
2 answers

Easiest way of unit testing C code with Python

I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any…
Jon Mills
  • 1,855
  • 4
  • 19
  • 28
24
votes
12 answers

Installing pocketsphinx python module: command 'swig.exe' failed

I'm getting something like this. Can anyone please tell me how to fix this. C:\Users\krush\Documents\ML using Python>pip install pocketsphinx Collecting pocketsphinx Using cached pocketsphinx-0.1.3.zip Building wheels for collected packages:…
Krushi Raj
  • 528
  • 1
  • 4
  • 14
24
votes
1 answer

SWIG and C++ memory leak with vector of pointers

I am using SWIG to interface between C++ and Python. I have created a function which creates a std::vector of object pointers. The objects that are pointed to are not important in this case. The problem I have is that when the object (someObject)…
Jason
  • 285
  • 3
  • 6
23
votes
1 answer

Generating Java interface with SWIG

I'm using SWIG to make a Java wrapper of a C++ library (about Json (de)serialization) to use it on Android. I defined an abstract class in C++, representing an object which can be (de)serialized : class IJsonSerializable { public: virtual void…
Marc Plano-Lesay
  • 6,808
  • 10
  • 44
  • 75
23
votes
4 answers

How to install SWIG?

Noob question ahead... I'm trying to install SWIG on Windows. According to the INSTALL document, I have to cd to the directory containing the package's source code and type ./configure to configure the package for your system. I tried the command…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
23
votes
10 answers

Import error: DLL load failed in Jupyter notebook but working in .py file

I installed BreakoutDetection the module in Anaconda environment. When I tried to import the module using import breakout_detection in jupyter notebook, I get the below…
nth-attempt
  • 649
  • 1
  • 5
  • 12
23
votes
2 answers

Dynamically rethrowing self-defined C++ exceptions as Python exceptions using SWIG

Situation I want to create a Python language binding for a C++ API using SWIG. Some of the API functions may throw exceptions. The C++ application has a hierarchy of self-defined exceptions, like this example: std::exception -> API::Exception …
tbacker
  • 772
  • 7
  • 22
22
votes
4 answers

Exposing a C++ class instance to a python embedded interpreter

I am looking for a simple way to expose a C++ class instance to a python embedded interpreter. I have a C++ library. This library is wrapped (using swig for the moment) and I am able to use it from the python interpreter I have a C++ main program…
jineff
  • 472
  • 4
  • 16
22
votes
7 answers

Prototyping with Python code before compiling

I have been mulling over writing a peak-fitting library for a while. I know Python fairly well and plan on implementing everything in Python to begin with but envisage that I may have to re-implement some core routines in a compiled language…
Brendan
  • 18,771
  • 17
  • 83
  • 114
22
votes
1 answer

Compiling C++ with SWIG on Mac OS X

I am trying to compile a C++ extension using Swig for Mac OS X. I have run into a few linker errors though. The basic tutorial for Python Swig also seems to fail on Mac: http://www.swig.org/Doc1.3/Python.html#Python_nn10 swig -c++ -python…
Nick S.
  • 1,643
  • 1
  • 12
  • 13
22
votes
1 answer

How to create a DLL with SWIG from Visual Studio 2010

I've been trying for weeks to get Microsoft Visual Studio 2010 to create a DLL for me with SWIG. If you have already gone through this process, would you be so kind as to give a thoughtful step-by-step process explanation? I've looked everywhere…
user1449530
  • 407
  • 2
  • 6
  • 10
21
votes
3 answers

Python SVN bindings for Windows

Where can I find precompiled Python SWIG SVN bindings for Windows?
Joshua
  • 26,234
  • 22
  • 77
  • 106
21
votes
3 answers

What are the best practices when using SWIG with C#?

Has anybody out there used the SWIG library with C#? If you have, what pitfalls did you find and what is the best way to use the library? I am thinking about using it as a wrapper for a program that was written in C and I want to wrap the header…
Dale Ragan
  • 18,202
  • 3
  • 54
  • 70
21
votes
3 answers

python distutils not include the SWIG generated module

I am using distutils to create an rpm from my project. I have this directory tree: project/ my_module/ data/file.dat my_module1.py my_module2.py src/ header1.h …
microo8
  • 3,568
  • 5
  • 37
  • 67
20
votes
1 answer

Swig python - c++ how to use type int8_t

I have a C function that takes as paramenter an 8 bit integer int8_t foo( int8_t x ); I would like to call this function from my python code using a swig interface but int8_t type do not exists in python. In order to have this kind of types exists…
Stefano
  • 3,981
  • 8
  • 36
  • 66