Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks.

I want to know if it's possible and how hard would it be to call functions from a C++ library(.so|.dll) from perl.

As I searched, a XS interface seems like the solution, but it's a rather big library(see CLAM) so I think do a interface for such a big library wouldn't be feasible.

Anyway, I decided to post this and ask for directions in what would be better in this case.

Thanks.

Replies are listed 'Best First'.
Re: C++ bindings ?
by Khen1950fx (Canon) on Mar 13, 2010 at 23:15 UTC
      I don't see how.
      Is there a way to specify external C++ files and I'm missing ?

      Besides that, it looks like this module actually compiles the code in runtime, which is totally impracticable in this case =/
        Is there a way to specify external C++ files and I'm missing ?

        Yes:
        use Inline Config => INC => '-I/my/path', LIBS => '-L/your/path -lyourlib'; use Inline CPP => <<'END'; /* your C++ code */ END # your perl code
        See the Inline::CPP documentation - and the Inline::C-Cookbook documentation (as the same principles apply to C++).

        Cheers,
        Rob
        It only compiles once. It reuses the previously compiled library if the code hasn't changed.
Re: C++ bindings ?
by ikegami (Patriarch) on Mar 14, 2010 at 02:25 UTC
    I believe the purpose of h2xs is to automatically create XS code for a library.