swig

Proxying C#->C++ class wrappers using SWIG

只愿长相守 提交于 2020-01-02 13:28:13
问题 Say I have following C++ code: /* File : example.h*/ typedef void (__stdcall *CppCallback)(int code, const char* message); class CppClass { public: CppClass() {}; void call(CppCallback callback) { callback(1234, "Hello from C++"); } }; And then I have C# counterpart: /* File : example.cs */ using System; using System.Text; public delegate void CSharpCallback(int code, string param); public class App { static void Main() { CppClass cppClass = new CppClass(); cppClass.call((i, s) => { Console

Dynamic linking and Python SWIG (C++) works in C++ fails in python

可紊 提交于 2020-01-01 17:01:48
问题 I have a library for which I have created a python wrapper using SWIG. The library itself accepts user provided functions which are in an .so file that is dynamically linked. At the moment I'm dealing with one that I have created myself and have managed to get the dynamic linking working... in C++. When I attempt to run it in python I get undefined symbol errors. These symbols are ones that are not present in the provided .so file but are present in the main program (essentially they are the

How to handle exceptions from C++ via SWIG to Java

这一生的挚爱 提交于 2020-01-01 09:40:05
问题 We are implementing a wrapper on C++ code for exposure to Java clients. I have seen the SWIG documents about exception handling but what does this translate to in coding terms in the three layers (C++/SWIG/Java)? If anybody has working example(s) or advice, I would be grateful. 回答1: Since I've wrestled with this (see my blog from my profile, it's on python, SWIG, exceptions and directors but should help) let me give you a few pieces of advice: Don't send C++ exceptions up to the Java stack.

Pocketsphinx install fail? Raspberry Pi Zero (Raspbian Jessie)

一个人想着一个人 提交于 2020-01-01 07:50:32
问题 This will probably get tagged as a duplicate, but I haven't had any luck, so here we go. I'm trying to develop a "Jarvis" like setup with Python2.7. I', looking to use Pocketsphinx as part of that. I tried to do this on my Windows 10 machine, but Pocketsphinx requires Swig, and that utterly failed on the Windows 10 machine (I'm still working on that.) So, I moved over to my Raspberry Pi Zero, since that is where I will be looking to impliment the actual program anyways. I got Swig to install

Compiling a SWIG Python wrapper for a static library?

≡放荡痞女 提交于 2020-01-01 07:20:10
问题 This is a noob question. I'm trying to learn how to use SWIG to make a python interface for a C++ library. The library is a proprietary 3rd party library; it comes to me in the form of a header file (foo.h) and a static archive (libfoo.a). To simplify matters, I've cooked up an example which I think has the same pathology. Same error messages anyways. /* foo.hpp */ class TC { public: TC(); int i; private: }; For reference, here's foo.c. I only have the header and archive files for the real

Is it a good idea for me to learn Python before C or some other Compiler language? [closed]

半城伤御伤魂 提交于 2019-12-31 21:37:40
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Right now I am going through MIT's introduction to Computer Science course via OpenCourseWare. As a part of this course I am learning

Dynamically rethrowing self-defined C++ exceptions as Python exceptions using SWIG

眉间皱痕 提交于 2019-12-31 10:31:16
问题 Situation I want to create a Python language binding for a C++ API using SWIG. Some of the API functions may throw exceptions. The C++ application has a hierarchy of self-defined exceptions, like this example: std::exception -> API::Exception -> API::NetworkException -> API::TimeoutException -> API::UnreachableException -> API::InvalidAddressException The desired behavior is as follows: All exception types should have a matching Python class as wrapper . These wrapper classes should be valid

swig + mono : C# example errors of not finding the library

余生颓废 提交于 2019-12-31 03:15:12
问题 I use swig 2.0.1 + mono 2.6/2.8 on Mac OS X 10.6.4. The overall build is OK, and the build of the C# examples is also OK. The problem is that when I run the example (mono runme.exe), I always get the following errors. Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for examplePINVOKE ---> System.TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper ---> System.DllNotFoundException: example

Wrong values passed as parameter to C library using SWIG

∥☆過路亽.° 提交于 2019-12-31 03:03:28
问题 Following my three previous posts, I can now pass a managed array of struct to my wrapped method. Here is an extract from the files: // packer.i typedef struct { int width; // input int height; // input frame_t view; // output frame_t dest; // output } image_t; CSHARP_ARRAYS(image_t, image_t) %apply image_t INOUT[] { image_t *images } int pack(image_t *images, int nb_images, parameters_t params); Which generates a function with this signature: // packer_cs.cs public static int pack(image_t[]

Add members dynamically to a class using Lua + SWIG

我的未来我决定 提交于 2019-12-30 11:35:46
问题 This Lua code, creates a table and dynamically adds a new member. Running this I can get "hello" on the screen as expected: foo = {} foo.x = "hello" print(foo.x) But now I'm using SWIG to bind some C++ classes to Lua. For that purpose, in a test.i (SWIG module file) I created a simple class like this: %module test %inline %{ class Foo { public: Foo() { X = 0; } void SetX(int x) { X = x; } int GetX() { return X; } private: int X; }; %} Then I wrote a test Lua code like that: obj = test.Foo()