Katherine Rix | 19 Dec 19:27 2014
Picon

How can I include SWIG-wrapped C++ in Mono / Unity 3D on Windows?

Hello all,

My goal is to get a toy C++ library wrapped using SWIG, and accessible
to C# / Mono scripts in Unity (the game engine) on Windows.

Following a few SWIG- and Unity-specific tutorials I have generated
two DLLs in Visual Studio 2013 and added them to the Unity project.
But accessing the toy method at runtime is failing as follows...

DllNotFoundException: example
CSharpExampleLib.examplePINVOKE+SWIGExceptionHelper..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the
type initializer for SWIGExceptionHelper
CSharpExampleLib.examplePINVOKE..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the
type initializer for CSharpExampleLib.examplePINVOKE
CSharpExampleLib.example.fact (Int32 n)
SimpleController.Start () (at Assets/scripts/SimpleController.cs:10)

One atypical thing I needed to do was add the following library
references and namespace to the autogenerated C# wrapper files:

using System;
using System.Runtime.InteropServices;

namespace NameOfWindowsDll {
...
}

I made several attempts to correct common for causes of the
(Continue reading)

Spandan Sharma | 19 Dec 09:39 2014
Picon

Returning non-copyable objects


In C++11 I can have objects that are only movable and not copyable, eg., std::unique_ptr. If my function returns such an object then swig generated interface_wrap.cxx gives an error on compilation saying that copying was attempted for a non-copyable type (ie., deleted copy constructor called etc). 

How do I use this in swig ? 

eg., 

std::unique_ptr<int> f();

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 6 Dec 20:06 2014
Picon

Re: error CS0246: The type or namespace name `IDisposable' could not be found

It would be great if you submitted this as a SWIG github patch along with a testcase for inclusion in newer versions of SWIG.

William

On 30 October 2014 at 08:03, Mathieu Malaterre <mathieu.malaterre <at> gmail.com> wrote:
Thanks much William ! I had copy/paste std_map.i to implement support
for std::set in C#:

http://sourceforge.net/p/gdcm/gdcm/ci/a55d1870a633a4eade24e45533ab499b26a5c5ad/tree/Wrapping/Csharp/std_set.i

I'll do the diff with the current swig3.0/csharp/std_map.i and should be done.

Thanks again,

On Thu, Oct 30, 2014 at 8:21 AM, William S Fulton
<wsf <at> fultondesigns.co.uk> wrote:
> Just to be a bit more clear, you should aim to modify your .i file to fully
> qualify your use of IDisposable to 'global::System.IDisposable'. I don't
> know where this is coming from, but it is likely to be from a 'csinterfaces'
> or 'csinterfaces_derived' typemap in your .i file. If you fully qualify
> IDisposable, it will still work when using SWIG 2.
>
> William
>
> On 30 October 2014 07:06, William S Fulton <wsf <at> fultondesigns.co.uk> wrote:
>>
>> See the CHANGES file entry for 3.0.0:
>>
>> 2013-11-09: wsfulton
>>             [C#] Apply patch #79 from Brant Kyser
>>               - Remove using directives from the generated C# code and
>> fully qualify the use of all .NET
>>                 framework types in order to minimize potential name
>> collisions from input files defining
>>                 types, namespace, etc with the same name as .NET framework
>> members.
>>               - Globally qualify the use of .NET framework types in the
>> System namespace
>>               - Remove .NET 1.1 support, .NET 2 is the minimum for the C#
>> module
>>
>>             This is a potential backwards compatibility break if code has
>> been added relying on these using
>>             statements that used to be generated:
>>
>>               using System;
>>               using System.Runtime.InteropServices;
>>
>>             The quick fix to add these back in is to add the
>> -DSWIG2_CSHARP command line option when
>>             executing SWIG. See CSharp.html documentation for more info.
>>
>>             *** POTENTIAL INCOMPATIBILITY  ***
>>
>> William
>>
>> On 29 October 2014 08:14, Mathieu Malaterre <malat <at> debian.org> wrote:
>>>
>>> Dear all,
>>>
>>> I am the maintainer of the GDCM package. It currently uses SWIG to
>>> generate its C# API. Some users recently reported that GDCM now fails
>>> to build using recent SWIG 3.x release (SWIG 2.x were fine). The error
>>> is:
>>>
>>> TagSetType.cs(11,27): error CS0246: The type or namespace name
>>> `IDisposable' could not be found. Are you missing `System' using
>>> directive?
>>>
>>>
>>> Where:
>>>
>>> [...]
>>> $ head -12 ./Wrapping/Csharp/TagSetType.cs
>>> /*
>>> ----------------------------------------------------------------------------
>>>  * This file was automatically generated by SWIG (http://www.swig.org).
>>>  * Version 3.0.2
>>>  *
>>>  * Do not make changes to this file unless you know what you are
>>> doing--modify
>>>  * the SWIG interface file instead.
>>>  *
>>> -----------------------------------------------------------------------------
>>> */
>>>
>>> namespace gdcm {
>>>
>>> public class TagSetType : IDisposable
>>> #if SWIG_DOTNET_3
>>> [...]
>>>
>>> My question is:
>>>
>>> - Should I add the missing `using System` using swig macros ?
>>> - Is there a documentation for migrating from swig 2.x to swig 3.x ?
>>>
>>> Thanks much,
>>>
>>> ref: https://github.com/malaterre/GDCM/issues/10
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Swig-user mailing list
>>> Swig-user <at> lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>
>>
>



--
Mathieu

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Kevin Smith | 6 Dec 15:21 2014
Picon

How to add a pure Python extension function to a SWIG'd module?

I have a function that I'd like to add to a SWIG'd module that is a pure Python extension function (i.e.,
argument parsing and validation is done by the function already).  Is there a way to add it to a SWIG wrapped
module and just have it be added to the module without modification?

Kevin D Smith
Kevin.Smith <at> sas.com

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
Kevin Smith | 4 Dec 22:59 2014
Picon

Getting a reference to a Python SWIG class from C extension

I need to write a C extension function to add to a SWIG'd module.  The function itself is wrapped by SWIG, so it
handles all of the argument parsing and such.  Inside this function, I'm calling all of the Python C APIs
directly for performance reasons.  However, one of the functions that I need to call from within this
function takes a SWIG class instance.  I have the underlying C structure, but I need to convert it to the SWIG
version so that it's a Python object for the function arguments.  Is there a way to do this?

This is basically what I want.  I'm just not sure how to convert the arg1->myStruct to the SWIG wrapped
version of that object.

PyObject *myfunc( MyArg *arg1, MyOtherArg *arg2 )
{
     PyObject *args = PyTuple_New(1);
     PyObject *kwargs = PyDict_New();
     PyObject *swig_obj = NULL;

     ... heavy lifting ...

     swig_obj = CONVERT_TO_SWIG_MYSTRUCT( arg1->myStruct );

     PyTuple_SET_ITEM(args, 0, swig_obj);

     return PyInstance_New(MyObject, args, kwargs);  
}

Kevin D Smith
Kevin.Smith <at> sas.com

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
Marc Spiering | 4 Dec 16:02 2014
Picon

nested templates, error during compilation of swig output

Hello,
I would need your help to get this nested template example (with full code below) swigged and compiled:
swig -c++ -java tmp.i # no problem
g++ -c tmp_wrap.cxx   # many errors, see below

This is a very much simplified example. The original code, which I want to wrap in java, uses a few nested
templates to generate some hundred classes. For this reason I am looking for a solution to the compilation
errors below, not for some workaround by explicitly writing out all template instantiations or whatever.
Of course, I would rewrite the '%include "tmp.cpp"' inside tmp.i if some minor corrections are necessary,
so that swig will get around the compilation errors. But the general structure of the definitions of A and B
should remain the same.
Is this possible?

Thank you
Marc

====== tmp.cpp ========
template<class T> class A{
public:
  A(){};
};

template<class T1,template<class> class T2> class B{
public:
  B(T2<T1> B){};
};
==== end of tmp.cpp ====

====== tmp.i ========
%module tmp;
%{
#include "tmp.cpp"
%}

%include tmp.cpp
%template(doubleB) B<double,A<double>>;
==== end of tmp.i ====

These are the error messages from the compilation of tmp_wrap.cxx:

$ g++ -c tmp_wrap.cxx -I$JDK_HOME/include -I$JDK_HOME/include/linux
tmp_wrap.cxx: In function ‘jlong Java_tmpJNI_new_1doubleB(JNIEnv*, jclass, jlong)’:
tmp_wrap.cxx:223:3: error: ‘T2’ was not declared in this scope
   T2< double> arg1 ;
   ^
tmp_wrap.cxx:223:7: error: expected primary-expression before ‘double’
   T2< double> arg1 ;
       ^
tmp_wrap.cxx:223:7: error: expected ‘;’ before ‘double’
tmp_wrap.cxx:224:7: error: expected primary-expression before ‘double’
   T2< double> *argp1 ;
       ^
tmp_wrap.cxx:224:7: error: expected ‘;’ before ‘double’
tmp_wrap.cxx:225:25: error: type/value mismatch at argument 2 in template parameter list for
‘template<class T1, template<class> class T2> class B’
   B< double,A< double>> *result = 0 ;
                         ^
tmp_wrap.cxx:225:25: error:   expected a class template, got ‘A<double>’
tmp_wrap.cxx:225:35: error: invalid type in declaration before ‘=’ token
   B< double,A< double>> *result = 0 ;
... error messages truncated here ...

Versions are:
SWIG Version 2.0.10
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
but I have also tried swig 3.0 		 	   		  
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
Laine, Mikael | 3 Dec 03:35 2014
Picon

Callbacks support for SWIG

We are considering using SWIG for a JavaScript apps development environment, but require callbacks from a
C++ API to the JavaScript wrapper.

Is there something on the roadmap for this?

If not, we could potentially contribute to the project for callbacks.

-Mikael Laine / Lead Software Developer

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
Martin, Paul | 28 Nov 16:06 2014

SWIG and polymorphic C# using %typemap

Hi,

I would like to support downcasting in a SWIG-generated C# project.

I have a series of C++ std::shared_ptr-wrapped class templates that inherit from a common base. Any C++ method that returns a base class (IBasePtr) in C++ code results in a generated method that returns a concrete IBase object, which has no relation to the object I am actually trying to get. The blog post here deals with this exact problem by inserting custom code to perform a downcast based on object type metadata.

The part I am struggling with is the use of SWIG's %typemap command. I have implemented some custom code that takes care of the casting and this is generated and compiles without any problem.%typemap is intended to instruct SWIG to map input and target types, in my case via the code to perform an explicit conversion:

 

%typemap(csout, excode=SWIGEXCODE)

IBase,

IBasePtr

MyLib::IBase,

MyLib::IBasePtr

{

    IntPtr cPtr = $imcall;

    $csclassname ret = ($csclassname) $modulePINVOKE.InstantiateConcreteClass(cPtr, $owner);$excode

    return ret;

}

 

The method InstantiateConcreteClass is generated but there are no references to it.  Any attempt to statically case an IBase to a CDerived fails.

Is there a vital step I am missing? I wondered whether the was some additional complication due to the use of shared_ptr in native code, but I don't think this is the case.

 

Thanks.

'************************************************************************************** This e-mail and any attachments thereto may contain confidential information and/or information protected by intellectual property rights for the exclusive attention of the intended addressees named above. If you have received this transmission in error, please immediately notify the sender by return e-mail and delete this message and its attachments. Unauthorized use, copying or further full or partial distribution of this e-mail or its contents is prohibited. **************************************************************************************
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
haianh | 26 Nov 11:22 2014
Picon

LEF/DEF interface with TCL

Hi all,

I have a research to build LEF/DEF interface with TCL using SWIG. The
reference project is at:

http://embedded.eecs.berkeley.edu/Alumni/pinhong/scriptEDA/
and http://www.openeda.org/openeda.si2.org/projects/lefdef

I have error when try to use SWIG 3.0.2 or 1.3.40 to compile LEF/DEF parser
5.7 with TCL. It said:

DEF.i:179: Error: Syntax error in input(1).
make: *** [DEF_wrap.c] Error 1

And I'm stuck to figure out what is problem. Can anyone who have experiment
with SWIG help me please?

I create my project at https://code.google.com/p/lef-def-interface-with-tcl/
and put my code to it. Anyone can download, run it and give me some advise.

Thank all very much. I'm looking for your help.

Hai Anh

--
View this message in context: http://swig.10945.n7.nabble.com/LEF-DEF-interface-with-TCL-tp14084.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
Yunkai Zhang | 25 Nov 16:23 2014
Picon

How can I wrap std::tr1::share_ptr for golang?

Hi folks:

I want to use swig to wrap our product library C++ API into Golang.

I have read some documentations about wrapping shared_ptr in swig, it seems swig can wrap it to java/tcl/python, but not support Golang now?

Can anyone tell me how to do it, we really need it.

Very Thanks!



--
Yunkai Zhang
Work at Taobao
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
giorgi | 21 Nov 15:01 2014
Picon

pass a Python function as argument of a c++ function

Hi,

I'm learning how to use swig to wrap c++ libraries for python.
I'm trying to pass a Python function as argument of a c++ function, but I guess i'm missing something.

Here is my Header funct.hpp

#include <functional> using namespace std; int myfun(int a, int b, function<int(int,int)> f);

Here the Source funct.cpp

#include "funct.hpp" int myfun(int a, int b, function<int(int,int)> f){ return f(a,b);}

The swig file funct.i

%module funct %{ #include "funct.hpp" %} %include "funct.hpp"

The setup.py file is

#!/usr/bin/env python from distutils.core import setup, Extension funct_module = Extension('_funct', sources=['funct_wrap.cxx', 'funct.cpp'], extra_compile_args=['-std=c++11'] ) setup (name = 'funct', version = '0.1', author = "SWIG Docs", description = """Simple swig example from docs""", swig_opts=['-c++'], ext_modules = [funct_module], py_modules = ["funct"], )

Then i try to test the wrapped module executing test.py:

def add(x,y): return x+y import funct x = funct.myfun(1,2,add) print x

but I get the following error

Traceback (most recent call last): File "test.py", line 6, in <module> x = funct.myfun(1,2,add) TypeError: in method 'myfun', argument 3 of type 'function< int (int,int) >' I read the Pointers and callbacks reference but I didn't manage to make it work, I think i have to add something in the funct.i file, but i don't know what and how.

Can anybody help me with this? Thanks in advance!

Daphné


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane