Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

how to create a Perl module

by bfdi533 (Friar)
on Aug 05, 2003 at 19:31 UTC ( [id://281131]=perlquestion: print w/replies, xml ) Need Help??

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

I have a C library that I have been using quite extensively for creating postscript graphs for many years. The problem is that the more I learn about Perl, the more I know I could improve my existing programs in C to be more powerful and more flexible.

Here is the question: What is the basic procedure for creating a Perl Module that converts a C library into Perl subs?

Ed

Replies are listed 'Best First'.
Re: how to create a Perl module
by Juerd (Abbot) on Aug 05, 2003 at 19:35 UTC
      And if you are under Win32, you can just do a Dll with
      your C code and call it using Win32::Api.
      It's a fast work.

        That would not actually work too well as this is a unix/linux C library and the C code is on linux. Good thought though that I will remember for the future.

        Ed

Re: how to create a Perl module
by Azhrarn (Friar) on Aug 06, 2003 at 05:44 UTC
    SWIG is a quick and easy way to generate perl stubs for your C/C++ programs. You just need to make a small swig.defs file that defines the exported parts of your C program. Then SWIG will make a C header file, and basic perl module that "just works".

    Or you can do a bunch of XS stuff if you're feeling masochistic.

      I'll second this - SWIG is an amazingly easy and powerful tool. One thing to note - IIRC, only basic data types like strings, integers, and floats can be passed back and forth, so if you want to pass structs back and forth you'll need to write some gettor/settor functions in C, because otherwise the structs will be blind references. You may need some constructor/destructor functions as well to allocate/free memory.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://281131]
Approved by Juerd
Front-paged by hsmyers
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-03-19 06:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found