I have posted this question to the inline mailing list, but haven't seen any response. I thought I would try my fellow monks to see if they could offer a clue.

I have been playing with Inline::C, trying to wrap an API so I could access it via perl. I have read the docs for Inline::C and explored the cookbook enough to figure out what I needed to do. I have been also able to get the examples contained within the cookbook working.

I wrote my code and, after getting rid of several stupid typos ( I am still trying to convince my fingers to stop adding a "$" in front of variable names :), the code compiled but returned an error. I worked at it for a little while and then decided to extract the C code, write a simple main() and see what happened.

It compiled, ran and returned without the error.

I am now very confused. I am dead certain I have missed something very silly - this is the first time I have tried to use Inline and my three previous attempts at using XS all failed

This is the code:

#!/usr/local/bin/perl -w use strict; use Inline C => Config => LIBS => "-lpdadminapi", PREFIX => 'my_', INC => "-I/usr/include/PolicyDirector"; use Inline C => << 'END_C'; #include <ivadminapi.h> /* So named in case there is some conflict of which I am unaware */ int my_create_context( char* user, char* passwd ) { ivadmin_context ctx; ivadmin_response rsp; unsigned long status; int i; printf("Establising context as %s (%s)\n", user, passwd ); /* This is the call that is failing */ status = ivadmin_context_createdefault(user,passwd,&ctx,&rsp); if ( ivadmin_response_getok(rsp) ) { printf("ivadmin_context_createdefault succeeded\n" ); } else { for(i=0; i<ivadmin_response_getcount(rsp);i++) { printf( "ivadmin_context_createdefault : (%d) %s\n", ivadmin_response_getcode( rsp, i ), ivadmin_response_getmessage( rsp, i ) ); } } ivadmin_free( rsp ); return status; } END_C my ( $foo, $user, $passwd ); $user = 'xxxxxxxx'; $passwd = 'xxxxxxxx'; $foo = create_context( $user, $passwd ); print "status = $foo\n";
And this is the main() I wrote to test the C code directly:
int main() { int stat; stat = create_context("xxxxxxxx", "xxxxxxxx" ); printf( "Stat = %d\n", stat ); return 0; }
If anybody could give me a pointer, I would appreciate it to no end. Again, I am quite certain this is my mistake but I really have no idea how to approach it.

Thanks,
mikfire


In reply to Inline::C code doesn't work, but the C code does by mikfire

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.