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

Hi Monks,
How can I integrate C/C++ APIs in my Perl program? Basically, I want to use certain C/C++ API functions in my Perl program. Please advise.
Thanks, Raj

Replies are listed 'Best First'.
Re: Perl and C/C++ APIs
by jbrugger (Parson) on Jan 25, 2005 at 11:41 UTC
    You might also look at: Perl and C++ and Extending Perl (Using C from Perl).
    (Quote from the page:)
    If you want to use C source code (or a C library) from Perl, you need to create a library that can be either dynamically loaded or statically linked into your perl executable. (Dynamic loading is usually preferred, to minimize the number of different perl executables sitting around being different.) You create that library by creating an XS file (ending in .xs) containing a series of wrapper subroutines. The wrapper subroutines are not Perl subroutines, however; they are in the XS language, and we call such a subroutine an XSUB, for "eXternal SUBroutine". An XSUB can wrap a C function from an external library, a C function elsewhere in the XS file, or naked C code in the XSUB itself. You then use the xsubpp utility bundled with Perl to take the XS file and translate it into C code that can be compiled into a library that Perl will understand.
Re: Perl and C/C++ APIs
by edan (Curate) on Jan 25, 2005 at 11:35 UTC
Re: Perl and C/C++ APIs
by samizdat (Vicar) on Jan 25, 2005 at 13:18 UTC
    SWIG and XS are both usable ways of adding C++ libraries to Perl. It's also a great way to combine the flexibility of the Perl interpreter with compiled code for commercial applications.

    Check out CH. 20 of Advanced Perl Programming (O'Reilly, S. Srinivasan), the "Panther Book".

    Caveat: it takes a while to set up either of these environments, but integration is swift once you have done so. Each has its advantages and disadvantages. SWIG is simpler, but XS is much used for .pm's so it might be worth your time to study. C2: These are 'nix-based solutions, YMMV on Doze.
Re: Perl and C/C++ APIs
by zentara (Cardinal) on Jan 25, 2005 at 13:09 UTC
Re: Perl and C/C++ APIs
by saskaqueer (Friar) on Jan 26, 2005 at 03:46 UTC

    Also, take a look at Win32::API. It's kinda rough around the edges, but it works fine.