velVerlet1 has asked for the wisdom of the Perl Monks concerning the following question:
Ciao Monks:
Newbie here, and trying to do a somewhat ambitious project, so apologies if this is somewhat stupid.
I'm trying to create a perl interface to my C++ finite element code.
The basic structure of the code is as follows:
I have an initiator function
void init(int argc, char **argv, void **ptr);
which creates a new instance of my class and assigns a pointer to it (ptr)
I have several member functions such as
int version(void *ptr);
which returns the various properties i'm interested in (in this case, ptr->version)
I've created a shared C++ library (mylib.so) already.
In order to create the perl interface, I used SWIG with the following interface file:
%include "exception.i" %exception { try { $action } catch (const std::exception &e) { SWIG_exception_fail(SWIG_RuntimeError, e.what()); } } %module mylib %{ /* Put headers and other declarations here */ #include "library.h" %} %include "std_vector.i" %include "std_string.i" %include "library.h"
Then I run swig and compile, which all goes well.
My question:
I want to do something like the following in perl
my $control = new mylib;
print "version: " . $control->version() . "\n";
However, whenever I try to access any of my member functions, the code complains:
TypeError in method 'version', argument 1 of type 'void *' at ./test_swig.pl line 8.
So basically, the function version expects a pointer (to self I assume???) but I'm not sure how to pass a void pointer to the C++ init function from perl
Any pointers (no pun intended) would be appreciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: interface perl to C++ code with SWIG, re: void pointers?
by syphilis (Archbishop) on Aug 26, 2017 at 09:15 UTC | |
|
Re: interface perl to C++ code with SWIG, re: void pointers?
by syphilis (Archbishop) on Aug 27, 2017 at 00:56 UTC | |
|
Re: interface perl to C++ code with SWIG, re: void pointers?
by stevieb (Canon) on Aug 26, 2017 at 21:39 UTC |