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
1
vote
0 answers

How to use SWIG to wrap a C++ function which uses a reference to a vector of structs as input and output to be used in Python?

As the title question suggests, I am trying to use SWIG to wrap a function defined in C++ which has as one of its variables a reference to a vector of structures used as both input and output (common in C++) so that the function can be used in…
mlachut
  • 11
  • 1
1
vote
1 answer

Undefined symbols with add_swig_library

I tried to write a simple usage example of SWIG with CMake, but I get the following error message: Undefined symbols for architecture x86_64: "_My_variable", referenced from: _Swig_var_My_variable_get in examplePYTHON_wrap.c.o …
Aleph
  • 1,343
  • 1
  • 12
  • 27
1
vote
1 answer

How to access C++ typedef'd structures in python with SWIG interface

I am trying to configure my SWIG interface to expose all defined typedefs. Example: For the following in my C++ header file I want my python code to be able to create objects A, B, C, D, E. //MyHeader.h struct Common { uint8_t …
Paige
  • 33
  • 4
1
vote
1 answer

SWIG wrapper of C++ library for Python - submodules

I'm trying to wrap a C++ library into a Python3 interface using SWIG, and there is a problem I can't quite fix. This library has several namespaces, and I would like to make them modules of the library when wrapped in Python. Assume the following…
1
vote
2 answers

Trouble finding numpy.i

I'm wanting to wrap some c++ code in python using swig, and I need to be able to use numpy.i to convert numpy arrays to vectors. This has been quite the frustrating process, as I haven't been able to find any useful info online as to where I…
Otherness
  • 385
  • 2
  • 16
1
vote
0 answers

how to include std_string.i with swig c++ to c#

I tried to execute swig to convert c++ code to c#. I made the tutorial code follow swig-tutorial. During the build steps it failed to build. I think it is not included property. How can I include it? the following code is my tutorial…
kangfox
  • 143
  • 1
  • 1
  • 10
1
vote
0 answers

SWIG: C++ array variable to python list

I'm trying to wrap c++ code with SWIG3.0. I have a class inside a namespace with a 2d array. I need to access the values. I have something like this: //example.cpp namespace n { class c { double x[2][2] = { {1,…
Maxiba
  • 23
  • 3
1
vote
1 answer

How to use numpy.i in swig?

I'm trying to wrap some c++ code with python using swig and I need to send NumPy arrays into the c++ vector class for some processing. My problem is that I don't seem to be able to access "numpy.i" in my swig .i file. How can I import/include…
Otherness
  • 385
  • 2
  • 16
1
vote
0 answers

Redirecting output from a SWIG module

I'm using a SWIG module in a Python script and I would like to redirect/mute excess output printed on the screen by the module. I'm aware of the possibility to redirect stdout/stderr within the Python script, eg. using redirect_stdout from the…
ovlindho
  • 33
  • 4
1
vote
1 answer

C++ & Python: Pass and return a 2D double pointer array from python to c++

I want to pass a 2D array from Python to a C++ function and then return an array of the same type, same dimensions, to Python. I am aware this question has already been asked several times, but I haven't been able to find a relevant answer to my…
Joachim
  • 490
  • 5
  • 24
1
vote
0 answers

Nothing known about base class if custom template class used

I'm trying to wrap libsnark, a c++ project, to golang. I got the following warnings, SWIG:1: Warning 125: Use of the include path to find the input file is deprecated and will not work with ccache. Please include the path when specifying the input…
Kimi Wu
  • 309
  • 1
  • 4
  • 17
1
vote
1 answer

swig generated python wrapper for c code - IN_ARRAY and ARGOUT from numpy.array()

I'm trying to generate a python wrapper for my C code with swig4. As I do not have any experience I'm having some issues converting a numpy-array to a c array and returning a numpy-array from a c array. Here is my repository with all my…
1
vote
1 answer

Interfacing both Debug and Release DLLs with the same C# code in SWIG?

SWIG lets you specify the DLL to import in C# by using the -dllimport command line argument. What about importing a DLL whose name depends on whether it is a Debug version or a Release one? This happens with DLLs that follow the Microsoft convention…
Eleno
  • 2,864
  • 3
  • 33
  • 39
1
vote
1 answer

Change getCPtr() visibility of a shared_ptr

I am currently using swig to generate Java code. I have two swig modules (module1 and module2) that will create two packages (fr.package1 and fr.package2). The generated classes of fr.package2 needs to use the generated classes of the other package.…
Fifi
  • 467
  • 6
  • 17
1
vote
0 answers

How can I implement correct SWIG interface to wrap shared_ptr on struct?

I'm working on python wrapper for some C++ code. In order to generate such wrapper SWIG tool is used. Almost all code is wrapped perfectly and works as expected except one thing. C++ code contains function which returns smart_ptr to structure which…
Alx
  • 11
  • 3