Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: interface perl to C++ code with SWIG, re: void pointers?

by syphilis (Archbishop)
on Aug 27, 2017 at 00:56 UTC ( [id://1198093]=note: print w/replies, xml ) Need Help??


in reply to interface perl to C++ code with SWIG, re: void pointers?

After my initial gaff, I'll have another crack at providing something that might be marginally useful - and I second stevieb's request for more info.
Inline::CPP and (Inline::C) seem to be quite happy to directly access the library's version() function: Here's the Inline::CPP demo:
################ package FOO; use strict; use warnings; use Inline CPP => Config => BUILD_NOISY => 1, ; use Inline CPP => <<'EOC'; int version(void * p) { return 42; } EOC my $sv = 'whatever'; my $obj = bless \$sv, 'FOO'; print $obj->version(); ################
That works just fine and outputs '42'.
Of course, it's a little bit different in your case because version() is in a separate library, so your script would be something like:
################ package FOO; use strict; use warnings; use Inline CPP => Config => INC => '/path/to/include', LIBS => '-L/path/to/library -lmy_lib', BUILD_NOISY => 1, ; use Inline CPP => <<'EOC'; #include <my_lib.h> int wrap_version(SV * p) { return version(p); } EOC my $sv = 'whatever'; my $obj = bless \$sv, 'FOO'; print $obj->wrap_version(); ################
or, if you want to call the sub from perl as "version":
################ package FOO; use strict; use warnings; use Inline CPP => Config => PREFIX => 'wrap_', INC => '/path/to/include', LIBS => '-L/path/to/library -lmy_lib', BUILD_NOISY => 1, ; use Inline CPP => <<'EOC'; #include <my_lib.h> int wrap_version(SV * p) { return version(p); } EOC my $sv = 'whatever'; my $obj = bless \$sv, 'FOO'; print $obj->version(); ################
I think SWIG should be capable of providing the same result.

Cheers,
Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-03-28 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found