in reply to Using the perl API in C

perhaps there is something I have to feed the linker here?

-lperl, i.e. link against the perl library (either libperl.so or libperl.a (static) — if the linker finds both, the shared version takes precedence by default). Whether that's sufficient depends on what exactly you're trying to do.

See also perlembed.

Replies are listed 'Best First'.
Re^2: Using the perl API in C
by halfcountplus (Hermit) on Dec 20, 2010 at 19:53 UTC

    In fact "-lperl" was my first guess, but that was not found. I didn't realize it was in a non-standard path, so I added "-L/usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/CORE"; of course it's then not found at runtime, so I added a softlink into /usr/lib64.

    But now I'm getting segfaults on basic stuff that worked fine in an XS module. Eg:

    SV *r = newSVpv("hello world\0", 16);

    Leads to:
    Program received signal SIGSEGV, Segmentation fault.
    Perl_newSVpv (my_perl=0x0, s=0x400848 "hello world", len=16) at sv.c:6985
    6985 new_SV(sv);

    Grrrr....

      You'll probably also have to initialise the interpreter (perl_alloc(), perl_construct() - see perlembed for details), so memory management works.

      If you provide a self-contained sample of what you're trying to build, someone here might look into getting it to run... :)

        initialise the interpreter

        Yeah, silly me, I'm sure that would be true.

        a self-contained sample

        Nothing complicated, and I don't really need to do it this way, I can use XS.