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
16
votes
5 answers

Mixing C++ code from different compilers

Suppose I have two projects that I would like to link together: A C++ library compiled with Visual C++ to a DLL file. A C++ executable compiled with C++ Builder that uses the classes in the library. I realize that there is no standard C++ ABI and…
James Johnston
  • 9,264
  • 9
  • 48
  • 76
15
votes
3 answers

How to make my SWIG extension module work with Pickle?

I have an extension module for Python that uses SWIG as a wrapper and I try to serialize it with Pickle and I fail =) If anyone has a source of SWIG extension that can be pickled, would love to see it! It seems like I should implement __reduce_ex__…
alexanderkuk
  • 1,551
  • 2
  • 12
  • 29
15
votes
5 answers

Python can't install Box2D swig.exe failed with error code 1

I try to install Box2D on python but I get the error log: C:\>pip3 install Box2D Collecting Box2D Using cached https://files.pythonhosted.org/packages/cc/7b/ddb96fea1fa5b24f8929714ef483f64c33e9649e7aae066e5f5023ea426a/Box2D-2.3.2.tar.gz Building…
FoldFence
  • 2,674
  • 4
  • 33
  • 57
15
votes
2 answers

Trouble setting environment variables for CTest tests

I'm tasked with building python bindings for a c++-based project (using swig). The project uses cmake to build and ctest to test and the build and test of the bindings are supposed to be integrated into this. I've gotten the build to work and the…
M.Isenholt
  • 193
  • 1
  • 1
  • 8
15
votes
1 answer

How to create an OUTPUT typemap for a class type?

I've previously had trouble with trying to apply SWIG's OUTPUT typemaps to class types, and asked this previous question. The answers I got there were helpful, but still require me to ask SWIG to do something like: %apply exportedClassType& OUTPUT {…
SWilliams
  • 691
  • 7
  • 28
15
votes
2 answers

How to get SWIG to apply templates when wrapping a template class containing vectors?

I am trying to use SWIG to wrap (in C#) some c++ code that contains a template class that itself wraps a std::vector. I have seen various references on the internet on how to declare the templates for the vector types, but can't get this to work…
SWilliams
  • 691
  • 7
  • 28
15
votes
1 answer

creating PHP C/C++ extension modules using SWIG

I have written some C/C++ extension modules for PHP, using the 'old fashioned way' - i.e. by using the manual way (as described by Sarah Golemon in her book). This is too fiddly for me, and since I am lazy, and would like to automate as much as…
morpheous
  • 16,270
  • 32
  • 89
  • 120
15
votes
1 answer

SWIG and C++ shared library

I have a C++ library (let's call it mylib) which compiles to libmylib.so file in /usr/local/lib and I have a bunch of header files in a directory called my lib in /usr/local/include. Now the thing I wanted to do (for starters) is just use one of the…
Veles
  • 1,512
  • 4
  • 14
  • 28
14
votes
1 answer

what does the last argument to SWIG_NewPointerObj mean?

I have a compatibility library that uses SWIG to access a C++ library. I would find it useful to be able to create a SWIG-wrapped Python object inside this layer (as opposed to accepting the C++ object as an argument or returning one). I.e. I want…
Adam
  • 16,808
  • 7
  • 52
  • 98
14
votes
3 answers

CMake Error: Could NOT find SWIG (missing: SWIG_DIR)

I wanted to test out Pocketsphinx in Node.JS. It says I need to install Swig version 3.0.7 or above. I think I installed all the other dependencies correctly. I can even type Swig commands in the Terminal now, but I keep getting this error whenever…
MysteryPancake
  • 1,365
  • 1
  • 18
  • 47
14
votes
1 answer

C++ to C Wrapper using SWIG (for FLTK)

I need to generate wrapper to FLTK C++ classes to use it in pure C. I know, that SWIG can do that, and I know how to generate wrapper for C#, Python etc. But I do not know how to wrap C++ to C using SWIG. It's simple task, but I can't find the…
Artem
  • 225
  • 2
  • 6
13
votes
1 answer

How does SWIG wrap a map in Python?

I'm using SWIG 2.0 to create a Python wrapper for a C++ library. One method has an argument of type "const std::map&". SWIG happily generates a wrapper for it, but I can't figure out how to invoke the method. If I pass, for example, {"a":"b"} for…
peastman
  • 1,239
  • 1
  • 13
  • 18
13
votes
2 answers

replace c++ with go + swig

I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's a mistake in my question: I assumed cgo could also be used to access c++…
lhk
  • 27,458
  • 30
  • 122
  • 201
13
votes
5 answers

Wrap C struct with array member for access in python: SWIG? cython? ctypes?

I want to access a C function that returns a struct containing double arrays (where the lengths of these arrays is given by other int members of the struct) from python. The declaration is typedef struct { int dim; int vertices; int…
kynan
  • 13,235
  • 6
  • 79
  • 81
13
votes
2 answers

Swig tool and C++. Being too clever

http://www.swig.org/papers/PyTutorial98/PyTutorial98.pdf It comes from above link: I know that it is an old publication so it is possible that information is outdated. I would like to ask: "Seems to work fine with C++ if you aren't being too…
Gilgamesz
  • 4,727
  • 3
  • 28
  • 63