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
13
votes
1 answer

SWIG: How to wrap std::string& (std::string passed by reference)

I am using SWIG to access C++ code from Java. What is the easiest way to expose a std::string parameter passed by non-const reference? I have primitives passed by reference exposed as Java arrays, thanks to typemaps.i, and const std::string&s…
Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
13
votes
1 answer

Python.h not found using swig and Anaconda Python

I'm trying to compile a simple python/C example following this tutorial: http://www.swig.org/tutorial.html I'm on MacOS using Anaconda python. however, when I run gcc -c example.c example_wrap.c -I/Users/myuser/anaconda/include/ I…
Fra
  • 4,918
  • 7
  • 33
  • 50
13
votes
1 answer

How to wrap a c++ function which takes in a function pointer in python using SWIG

Here is a simplified example of what I want to do. Suppose I have the following c++ code in test.h double f(double x); double myfun(double (*f)(double x)); It doesn't really matter for now what these functions do. The important thing is that myfun…
Bluegreen17
  • 983
  • 1
  • 11
  • 25
13
votes
1 answer

SWIG errors because of preprocessor directive

We have a vendor that has provided us a C++ library and headers, that I'm trying to wrap using SWIG. It appears that they are being too clever by a half with the preprocessor directives: // top.h #define DECLARE_WITH_COMMA(a) a, and then //…
laslowh
  • 8,482
  • 5
  • 34
  • 45
12
votes
1 answer

SWIG wrapped vector of vectors (C++ to python) - how to recognise the inner vector as a proxy object?

I'm facing a similar issue to Wrap std::vector of std::vectors, C++ SWIG Python - but it's not just simple C++ parsing. I have the following in my C++ code namespace ns { typedef unsigned long long uint64_t; typedef std::vector
Danny S
  • 457
  • 4
  • 15
12
votes
0 answers

Wrapping C++ with Cython or SWIG --What's the Tradeoff?

I've read several threads about some of the differences between Cython and Swig and have implemented both techniques, but I am still not sure what route is the best route to take. Basically I have been working on a C++ library and I would like to…
user985030
  • 1,557
  • 1
  • 16
  • 32
12
votes
1 answer

Calling C function from Python (No Return Value)

I used SWIG to connect my C++ program with Python. From cFunctions.py I call C function named checkVal like following: lib = cdll.LoadLibrary('./test.so') xml_bytesTrx = bytearray(b'...') a1 =…
AJ-B29
  • 215
  • 1
  • 11
12
votes
3 answers

Matlab binding of a C++ library using SWIG

I am already using SWIG to port some C++ libraries in Python, and I am really impressed by the quality of the results. So I'd like to stick with SWIG.. Recently somebody asked me for a Matlab port. Such a idea was actually already in my todolist..…
gmas80
  • 1,218
  • 1
  • 14
  • 44
12
votes
1 answer

directory structure for a project that mixes C++ and Python

Say you want want to create a programming project that mixes C++ and Python. The Foo C++ project structure uses CMake, and a Python module is created by using Swig. The tree structure would look something like this: ├── CMakeLists.txt ├──…
aaragon
  • 2,314
  • 4
  • 26
  • 60
12
votes
1 answer

Javascript extension to use C based APIs(clutter) in a webapp

My goal is to use the C libraries to form web apps. I have chosen the way to do that via using "SWIG" tool. The Swig tool requires three things: .c file which defines all the functions. .i file also called interface file which is creating…
user1872227
  • 141
  • 3
12
votes
3 answers

What is Warning 503 by SWIG?

Please explain what are these warning by SWIG and how to avoid it? Warning 503: Can't wrap 'operator ()' unless renamed to a valid identifier. Warning 503: Can't wrap 'operator =' unless renamed to a valid identifier. Warning 503: Can't wrap…
arsalank2
  • 1,683
  • 1
  • 16
  • 25
11
votes
2 answers

How can I build this simple C++/SWIG/C# project in Visual Studio 2010?

I need help setting up a simple C++/C# SWIG project. I am having a hard time putting together a C++ project that uses the SWIG bindings. I'm using Visual Studio 2010 and the most recent version of SWIG. My code is simply: cpp_file.h: #pragma…
user1214135
  • 625
  • 2
  • 11
  • 22
11
votes
2 answers

SWIG (v1.3.29) generated C++ to Java Vector class not acting properly

I have some native C++ code that I'm converting to Java using SWIG so that my Java application can use it. In particular there are some functions that return std::vector. Here's a snippet of my interface file: %include "std_vector.i" namespace std…
sirmarlo
  • 217
  • 1
  • 3
  • 8
11
votes
2 answers

How to convert numpy arrays to vector& (reference) with SWIG

My goal: Create 3 numpy arrays in python (2 of them will be initialized with specific values), then send all three of them through swig into a c++ function as vector references (this is in order to avoid copying over the data and loosing…
Otherness
  • 385
  • 2
  • 16
11
votes
3 answers

SWIG C-to-Python Int Array

I am trying to access a C function with the following prototype from python using swig: int cosetCoding(int writtenDataIn, int newData, const int memoryCells, int *cellFailure, int failedCell); Swig creates the .so with no problems and I can import…
Adam
  • 463
  • 2
  • 6
  • 14