Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Glue C library to Perl

by leonb (Novice)
on Mar 23, 2004 at 15:09 UTC ( #339031=perlquestion: print w/replies, xml ) Need Help??

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

This is about finding a Monk who can lead me, step by step through gluing a C library to Perl. I have read the docs, but since I am new to Perl, and haven't touched C,I need a few more details than provided in the tech docs.


janitored by ybiC: Retitle from less-than-descriptive "Looking for Guidance" for better site searching, and minor format tweak for legibility

Replies are listed 'Best First'.
Re: Glue C library to Perl
by tachyon (Chancellor) on Mar 23, 2004 at 18:10 UTC

    Either ExtUtils::XSBuilder or h2xs will do most of the work for you reading the header(s) and or C source file(s) and writing the glue code. With XSBuilder see the POD here. While either of these will do most of the work you will be very lucky if you don't have to fine tune it yourself. HTH.

    As far as teaching you how to do your paid work goes by leading you by the hand through it forgive me for the lack of enthusiasm.



Re: Glue C library to Perl
by flyingmoose (Priest) on Mar 23, 2004 at 19:02 UTC
    since I am new to Perl, and haven't touched C
    monks -- I think our suggestions are probably a bit over Leon's head right now. Maybe we need to take a step back here.

    Leon -- first off, I'd recommend you get some books and learn Perl and C at least at an introductory level. Perl XS isn't going to be covered in those books, but you'll need the knowledge. Also, you'll need to understand C -- and since you haven't got a solid grasp on C yet -- I'm expecting even makefiles might be foreign to you. Perl is Unixy by nature, and so is C, so if you have neither this may be a hard road.

    Not to jump to conclusions, but I think you have bit off more than you can chew, and maybe, just maybe, you aren't the right person for this job? Your managers, etc, would probably be appreciative if you made them aware of this (what you still need to learn and what you are not familiar with), otherwise they will be knocking our your door later wondering where the code and is and why you are encountering problems. Can you get some Perl and C programmers to help you? Where does your expertise lie if you are doing Perl and C and aren't proficient at either? (i.e. how did you get drug into this?) Can you operate the C debugger if you must debug a C module? Are you prepared for the evils that may go wrong (seg faults, core dumps, pointer problems, etc)?

    I'm just saying this because XS is not the first thing someone does with Perl, and XS with C code requires, pretty much, that you understand C. If you must trudge forth, Inline::C will get you started and perhaps it can be written in XS later once you get the other quirks cleaned out.

    Also, rather than asking for someone to step you through this, perhaps you could post the docs you have looked at, and the monks can recommend some other references? Many of us would probably like to offer pointers, but we can't devote time to a 1:1 if that 1:1 is going to include multiple lessons on C basics, makefiles, and other non-Perl prerequisites (IMHO) that you need to do this particular job.

      You're assestment that I'm in the deep end of the pool is correct. My first program (after Hello) in Perl was a WEB site tester that is uses the HTTP agent, tests the site, pings the host if not found, and emails to a few people. I liked the Perl functionality and it still being low level enough for this type of work. Instead of tying up the good people here, maybe there is a site that has Perl Programmers listed and I could find one of them to help me. telling the maangers I am not the right person is fine, I just need to provide an alternative.
        I think you HAVE found a site that has perl programmers. Perhaps you could offer a "bounty" to have someone help you, or just write the code that you need.

        Very funny Scotty... Now PLEASE beam down my PANTS!
Re: Glue C library to Perl
by valdez (Monsignor) on Mar 23, 2004 at 15:17 UTC

    What library? Is it for fun or for profit? Have you checked on CPAN? Give us some more details please :)

    Ciao, Valerio

      This is a company project. I am going to be paid for it. We are using a Support Center application and need to post data to one of the tables. The table contains encrypted data, but the supplier provides a C library, code sample and library header files to use as examples to post to the table. I have been through CPAN and see that I need to work with XSUB, but need more detail.
Re: Glue C library to Perl
by EdwardG (Vicar) on Mar 23, 2004 at 15:21 UTC

    Hi leonb,

    You don't explain your motivation, but I can think of three reasons you might want a Monk leader

    1. For the learning experience
    2. For the end result
    3. For the companionship :-)

    If you explain your motivation better, I'm sure someone can help you.

      Yes, I have three motivations. The learning experience. I enjoy learning and have been through the lands of many languages. Definitely the end result. And more of an earthly motivator, I will get paid for it (willing to share some of this).
Re: Glue C library to Perl
by Aragorn (Curate) on Mar 23, 2004 at 16:04 UTC
    Glueing a C library to Perl is easier done with SWIG than with XS.


Re: Glue C library to Perl
by eserte (Deacon) on Mar 23, 2004 at 16:24 UTC
    Try Inline::C .

    Disclaimer: I am just in the process to convert a couple of modules from Inline::C to XS. Inline::C is nice for getting the work quickly done, but it is not optimal --- too slow in the compile process, you need extra dependencies, distribution of the generated libraries without using Inline::C is not possible out-of-the box.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2023-03-22 12:17 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.