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

Is there any way to use pythonappend with SWIG's new builtin feature?

I have a little project that works beautifully with SWIG. In particular, some of my functions return std::vectors, which get translated to tuples in Python. Now, I do a lot of numerics, so I just have SWIG convert these to numpy arrays after…
Mike
  • 19,114
  • 12
  • 59
  • 91
73
votes
21 answers

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader

Is there someone who had experience with this error? java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.swig.simple-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find…
developergg
  • 837
  • 1
  • 7
  • 12
70
votes
10 answers

Extending python - to swig, not to swig or Cython

I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance. With the help of swig you almost don't need to care about arguments etc. Everything works fine. Now my question: swig…
RSabet
  • 6,130
  • 3
  • 27
  • 26
63
votes
10 answers

Python: SWIG vs ctypes

In python, under what circumstances is SWIG a better choice than ctypes for calling entry points in shared libraries? Let's assume you don't already have the SWIG interface file(s). What are the performance metrics of the two?
Kevin Little
  • 12,436
  • 5
  • 39
  • 47
44
votes
7 answers

cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++

I am building a C++ extension for use in Python. I am seeing this warning being generated during the compilation process - when a type: python setup.py build_ext -i What is causing it, and how do I fix it? BTW, here is a copy of my setup…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
42
votes
5 answers

Exposing a C++ API to Python

I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program. The alternatives I tried…
Marcos Lara
  • 1,883
  • 5
  • 18
  • 20
38
votes
6 answers

How can I implement a C++ class in Python, to be called by C++?

I have a class interface written in C++. I have a few classes that implement this interface also written in C++. These are called in the context of a larger C++ program, which essentially implements "main". I want to be able to write…
hal3
  • 391
  • 1
  • 4
  • 4
36
votes
6 answers

How do I propagate C++ exceptions to Python in a SWIG wrapper library?

I'm writing a SWIG wrapper around a custom C++ library which defines its own C++ exception types. The library's exception types are richer and more specific than standard exceptions. (For example, one class represents parse errors and has a…
Barry
  • 485
  • 1
  • 4
  • 8
32
votes
1 answer

STL map in Perl using SWIG

This is duplicate of my question on SWIG mailing list. I am trying to use stl containers in my SWIG bindings. Everything works perfectly except for stl map handling in Perl. On C++ side, I have std::map TryMap(const…
alexanderkuk
  • 1,551
  • 2
  • 12
  • 29
31
votes
9 answers

Looking for a convenient way to call Java from C++

It seems most documentation or helper libraries relating to JNI (Java Native Interface) are concerned with calling native code from Java. This seems to be the main use of it, even though it is capable of more. I want to mostly work in the opposite…
Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
30
votes
10 answers

M2Crypto doesn't install in venv, or swig doesn't define __x86_64__ which breaks compiling against OpenSSL

I'm trying to install the Python M2Crypto package into a virtualenv on an x86_64 RHEL 6.1 machine. This process invokes swig, which fails with the following error: $ virtualenv -q --no-site-packages venv $ pip install -E venv…
Lorin Hochstein
  • 57,372
  • 31
  • 105
  • 141
30
votes
2 answers

Passing a C++ object to Python

This question is about how to pass a C++ object to a python function that is called in a (C++) embedded Python interpreter. The following C++ class (MyClass.h) is designed for testing: #ifndef MyClassH #define MyClassH #include using…
Totte Karlsson
  • 1,261
  • 1
  • 20
  • 55
29
votes
1 answer

Why can't I get swig wrap std::vector to Ruby class?

I have an application with an embedded Ruby interpreter, and interfaces to STL classes generated by swig. Pretty much everything worked out fine thanks to swig, except for one thing: %module Stuff %import "std_vector.i" namespace std { …
jackson
  • 291
  • 2
  • 3
29
votes
1 answer

Passing a string to agedge in agraph.py. Issue with networkx and pygraphviz

Given this initial graph: import networkx as nx G=nx.MultiGraph() fromnodes=[0,0,1,1,1,1,1,2,3,4,5,5,5,7,8,9,10] tonodes=[1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] dupedgeind=0 for x,y in zip(fromnodes,tonodes): if G.has_edge(x,y): …
Lee
  • 29,398
  • 28
  • 117
  • 170
29
votes
8 answers

How should I unit test a code-generator?

This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions. I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and…
jkp
  • 78,960
  • 28
  • 103
  • 104
1
2 3
99 100