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.
3,068
questions
-1
votes
0
answers
19
views
How can I make a python wrapper for the c++ RPLiDAR library? [closed]
While doing some research for a school project involving Slamtech's A1M8 LiDAR scanner, I came across this Python wrapper for their C++ library. The code is a bit outdated, and I could find no way to ...
0
votes
1
answer
22
views
Swig Python - python scripts stops when PyErr_SetNone(PyExc_StopIteration) is raised
I coded a small container in C++, custom_vector. I want it to be iterable. Here is my swig interface file:
%template(vectorModelDescriptor) com_cae::physiology::vector<::IModelDescriptor*>;
%...
1
vote
0
answers
96
views
Don't understand how Python calls this C function
please be patient , I am just trying to learn Python, but trying to figure out how some software works ( https://github.com/LBC-LNBio/pyKVFinder/tree/master ) .
Here in https://github.com/LBC-LNBio/...
-2
votes
0
answers
28
views
windows swig python dll couldn't load issue
i have made a python/c++ project on windows msvc. the project is bellow:
enter image description here.
the cmakelists is bellow:
enter image description here
i make sub as a dll and linked by ...
0
votes
1
answer
33
views
Converting c++ array to python list using SWIG
I would like to have a method in C++ that returns an array of uint8_t, and then using SWIG make the function available in python as a list, something like:
class MyClass
{
uint8_t array_return() {
...
0
votes
1
answer
33
views
Getting the csinterface_derived to work when swiging C# interfaces
I have the following class inheritance pattern in a c++ header file.
class Base{
public:
virtual ~Base() = default;
};
template<class T> class Container : public Base{
public:
~Container ...
0
votes
0
answers
33
views
Swig-Doxygen translation lines still appear on C++ script
I am using swig to generate wrapper Python function for C++ based application. when using swig, I am using -doxygen option to translate doxygen document to python wrapper file. Inside C++ header file, ...
0
votes
1
answer
74
views
Android app crashes on load library, cannot find entry point getThreadLocalsEv, how to fix? [example added]
My code is crashing on System.loadLibrary("hypoboleus"); with an error that it cannot find an entry point. I have created a so file and included it in the app/src/main/jniLibs/arm64-v8a/ ...
1
vote
0
answers
27
views
How to pass null pointer (double pointer) to c function via java jni?
There is the following function in shared library (dll):
intptr_t GetClassObject(void** pptr)
{
if(!*pptr)
{
int value = 10;
*pptr= &value; //here is another code like new ...
0
votes
1
answer
45
views
SWIG Interface for calling Qt from Python
I try to call a C++ function from Python but I get:
TypeError: in method 'drawColorWheel_NoPerf', argument 2 of type 'QPainter *'
I use swig2.0.
The Python script:
SmallExample.py
#!/usr/bin/env ...
0
votes
0
answers
36
views
Print a 2-dimensional array returned by SWIG interface in Python using swig methods
I have the following C structure:
typedef struct _myS
{
int x;
int y;
} myS;
typedef struct _MyData
{
int a[10][10];
myS s[10][10];
} MyData;
It is filled by a C implementation and returned ...
0
votes
1
answer
49
views
Getting char* and size_t from C to ruby, and pass them from Ruby to C without FFI (using SWIG)
I have question because I'm out of ideas here. I have c library wrapped with SWIG. I do not use FFI because I don't want to have any 3rd party dependencies in my GEM. The thing is I faced some problem....
0
votes
0
answers
28
views
Multiprocessing passing a PySwig Object
I am trying to do some multiprocessing in python using the PySAGA module. In order to avoid having to load the input raster for each worker I am trying to pickle the loaded raster to the ...
0
votes
0
answers
29
views
How can I use CMake to link C++ packages to SWIG wrappers?
I am trying to build a simple program that uses C++ packages in Golang. I decided to use CMake and SWIG to handle the linking and Golang module generation. The program works fine when I am using C++ ...
1
vote
0
answers
32
views
Transform numpy.ndarray into "Eigen::Vector3d" data type through SWIG
I am trying to wrap a function whose argument is an "Eigen::Vector3d" data type, nevertheless, I would like to transform a NumPy ndarray into it. I suppose I would need to use a typemap in ...
0
votes
0
answers
194
views
Building a Python library from a c++ program?
I'm still incredibly new to all of this, so I apologize if I'm not providing the correct info, or presenting my issues properly.
Python Version: [3.11]
Operating System: [Windows 11 x64]
Ebsynth .dll/...
0
votes
0
answers
49
views
How can I properly use CMake and SWIG to generate a .dll that can be used on go?
I am trying to create a .dll to use it in go, I am using CMake and Visual Studio. My plan was create and test the library in c++, then use SWIG and CMake to generate the go module and handle the ...
0
votes
0
answers
36
views
SWIG Python binding for std::vector<std::shared_ptr<Service>> results in invalid pointer error
I am trying to use SWIG to generate Python bindings for a C++ project. The project includes a class InterfaceServiceManager with a method requestServiceByType that returns a std::vectorstd::shared_ptr&...
0
votes
1
answer
22
views
How to typemap returned custom template?
I have a set of C++ image processing classes using
template <typename T> class PixelBuffer {... }
class ImageSource {
PixelBuffer<uint16_t> GetImage() const;
};
Ultimately I want to ...
-2
votes
1
answer
33
views
How python swig wrappers were generated without any source files in my case?
I was researching using C++ in Python with SWIG. I came across this repo. I installed as recommended with python -m pip install tesseract-robotics. I expected it to download C++ source code, generate ....
0
votes
0
answers
34
views
Passing array from C# to SWIG as Span<T>
I'm looking for a way to pass an array from C# to C/C++ code without additional data copy. At the first glance using built-in SWIG typemap for C# is a way to go. But there is a couple of things that ...
0
votes
0
answers
16
views
SWIG custom javacode class method not appearing in JNI
Using SWIG I'm trying to add a custom javacode method into a class.
The resulting wrapper code contains the method definitions that I want, but the JNI wrapper is missing the method declaration.
In my ...
2
votes
0
answers
58
views
Assigning python functions to C structure variables using SWIG
The problem I'm currently facing is to assign a python function to a C structure member variable that is a function pointer.
I get the error from the setter function generated by Swig when we call the ...
0
votes
1
answer
123
views
Could NOT find SWIG in Android Studio on Mac M1 Pro
I have Android project with C++ code and I'm using CMake 3.10, SWIG 4.1 and NDK 20.1.5948944.
On Windows it works fine but on Macbook I have troubles.
I have added environmental variables ...
0
votes
0
answers
71
views
Struggling to wrap C++ library in python with swig on Mac M1 (arm64 architecture)
I have a big library of C++ code that I have already wrapped in python on Ubuntu, dividing the wrap in different modules and everything works.
The problems start when I want to do the same operation ...
1
vote
0
answers
14
views
How to config SWIG interface to map a c++ data type in JNI to multiple data types
I'm new to SWIG, I'm using SWIG to generate a wrapper for a C++ library in Java. I have a C++ function float sum(aVector2). In my Java code, I want to pass two float values (x, y) to generated wrapper ...
0
votes
0
answers
48
views
Using setuptools to build swig-generated extension module with out-of-tree sources
I try to transition from automake/autoconf instructions to setuptools and setup.py to build a swig-generated Python wrapper for a C-library. I already found many instructions how that can be ...
1
vote
0
answers
26
views
How should declare SWIG interface if some types can be wrapped with either shared_ptr or just value type?
In SWIG, I tried to use shared_ptr as below.
class Member {
};
class Parent {
private:
std::shared_ptr<Member> member_;
};
class OtherParent {
private:
Member member_;
}
%...
0
votes
1
answer
46
views
SWIG turns 'bool' C type into a SWIGTYPE, even when including stdbool.h in interface file
SWIG generated a SWIGTYPE_p__Bool to use when c functions returned bool types. This seems incorrect.
Example C function returning bool:
bool
bitwuzla_sort_is_equal(const BitwuzlaSort *sort0, const ...
0
votes
1
answer
44
views
SWIG - problem with duplicated java files
Problem I'm trying to solve in shortest example looks like that.
I have 2 swig's interface files.
first swig file Common.i looks like that:
/* Common.i */
%module Common
%include "Common.hpp&...
0
votes
0
answers
20
views
Is it possible to implement java interface AudioTrack.OnCodecFormatChangedListener from cpp [duplicate]
We have a multimedia player SDK where all the source files are in CPP. We have a requirement that we need to register a listener with the android audioTrack by calling the following method
...
5
votes
0
answers
63
views
Why is the memory view of a numpy record readonly?
Why is Python telling me that the memory view of a record is readonly?
>>> x = np.zeros(1, dtype='d,d,i')
>>> x
array([(0., 0., 0)], dtype=[('f0', '<f8'), ('f1', '<f8'), ('f2', ...
0
votes
1
answer
37
views
SWIG typedef creates conflict across module boundary
I am writing a C# wrapper for the stepcode library (https://github.com/stepcode/stepcode) by using SWIG (version 4.1.1) as generator. The library is highly modularized, so there are situations where ...
0
votes
3
answers
58
views
How do I access the contents of a numpy record in C?
Suppose I create
descriptor = np.dtype([
('left', np.double, 3),
('center', np.double, 3),
('right', np.double, 3),
])
value = np.zeros(10, dtype=descriptor)
I can verify ...
1
vote
2
answers
42
views
How to create SWIG mapping for std::shared_ptr<double> to Java
What should be the proper SWIG mapping for the following function?
std::shared_ptr<double> getMinScale() const;
1
vote
1
answer
2k
views
How ot write a Faiss index to memory?
I want to write a faiss index to back it up on the cloud.
I can write it to a local file by using faiss.write_index(filename, f).
However, I would rather dump it to memory to avoid unnecessary disk IO....
1
vote
0
answers
48
views
SWIG incorrectly using a generated pointer type when generating Java code from C. How to change the interface file?
It seems like SWIG is generating a pointer type, which then is used even when only a value itself is needed by the function. It does this by creating a function requiring the pointer type in Java, ...
0
votes
1
answer
183
views
ImportError: DLL load failed while importing _pydna: The specified module could not be found
Update: I traced the line which is causing the problem.
Error is coming from dna.py file, from line code 15.
This is the code:
# Import the low-level C/C++ module
if __package__ or '.' in ...
0
votes
0
answers
35
views
Python equivalent to `PyArrayContiguousFromAny`?
Is there a Python equivalent to the C API's function:
PyArray_ContiguousFromAny(PyObject* op, int typenum, int min_depth, int max_depth)
numpy.ascontiguousarray(a, dtype) seems close, but it doesn't ...
0
votes
0
answers
48
views
How to use auto return type with SWIG
I want to write in c++ code like this and generate it's wrapper in java:
class A() {
public:
const auto & getNumbers() const { return _numbers; }
private:
vector<int> _numbers;
}
but ...
0
votes
0
answers
59
views
Using SWIG to create a Python wrapper on Linux
I created a swig wrapper c++ to python. I have install both files (python and .so file) but when I import my python file, this error occours:
Traceback (most recent call last): File "/home/root/...
0
votes
0
answers
23
views
SWIG & MarshalDirectiveException: Marshaling to and from COM interface pointers isn't supported
I'm using SWIG to store C# managed callback functions inside an unmanaged class. Then, I'm calling an unmanaged method (say, e.g., Execute()) that will call all managed functions passed earlier. ...
0
votes
1
answer
55
views
Python to C, SWIG design pattern for a function with input and output void pointer arguments
I have the following scenario:
Function header along with request and response structures:
struct request1 {
int a1;
int b1;
};
struct response1 {
int y1;
int z1;
};
struct request2 {
...
0
votes
1
answer
1k
views
ModuleNotFoundError: No module named 'swig' but swig is already imported
I'm setting up my virtual environment right now and I'm trying to install faiss-cpu. The problem is that I keep getting this error:
\`ERROR: Command errored out with exit status 1:
command: /scratch1/...
0
votes
1
answer
19
views
SWIG : convert item of a numpy array to a C++ typedef
Here is a minimal example (ubuntu 18.04, swig 4.2.0):
Var.hpp
#include <iostream>
typedef int MY_INT;
void printMyInt(MY_INT v)
{
std::cout << "MyInt is " << v << ...
1
vote
0
answers
54
views
Making a generic container typemap and accessing the template argument
Let's say I want to create a generic std::vector<T>* typemap. SWIG can do this if I do not specify any template argument.
Then I can access the full type, including its template argument by ...
1
vote
1
answer
55
views
Calling undefined number of callback functions from the C++ layer
Recently I started to use SWIG to develop a solution that passes (possibly) several callback functions that should be called in the C++ layer. Besides, I spent some time reading the introduction ...
0
votes
1
answer
14
views
Generic typemap that is applied to all named arguments except `this`
Does anyone know if it is possible to make a generic typemap (ie without argument names) that applies to all arguments of this type except this pointers.
Something that goes like
%typemap(in, nothis=1)...
0
votes
1
answer
37
views
How to inject code at the top and bottom of each method generated in cpp wrap file by SWIG?
I would like to add code to the SWIG generated wrappers in cpp wrap file. For example adding global mutex to prevent C# garbage collector from changing some shared variable.
SWIGEXPORT int SWIGSTDCALL ...
0
votes
1
answer
30
views
swig: how to ignore unnamed struct
I'm trying to swig third party code (i.e. I cannot modify that code). In one of the header files I'm including there is an unnamed struct inside a union as follows:
struct ThirdPartyStruct {
union ...