I have written code using XS without problems. In all those programs I have written the C-code into the xs file. But now, I have tried to use a function defined in an other shared-object file, and although the building process does not print errors, when I use the pm-module (in "make test" for example) it returns "undefined symbol" error. During the shared-object building, make-process shows me the following message: "linker input file unused because linking not done". This warning explains the previous error. In C-code the symbols are resolved in executable files, not in shared-objects. But Perl import C-code as a shared-object, and so how can I resolve this problem??

-----------------------/tmp/prova2/helloworld/Makefile-----------------------
# Makefile MODULE=helloworld TYPEMAP=/usr/local/lib/perl5/5.8.7/ExtUtils/typemap XSUBPP=/usr/local/lib/perl5/5.8.7/ExtUtils/xsubpp PERLCORE=/usr/local/lib/perl5/5.8.7/i686-linux/CORE CC=gcc .PHONY: init clean all : init libhelloworld.so init : perl -e "use Devel::PPPort; use ExtUtils::Constant q +w (WriteConstants); \ Devel::PPPort::WriteFile(); WriteConstants(NAME => ' +$(MODULE)')" libhelloworld.so : helloworld.o $(CC) -shared helloworld.o -o $@ helloworld.c : helloworld.xs perl $(XSUBPP) -typemap $(TYPEMAP) helloworld.xs >$@ helloworld.o : helloworld.c $(CC) -Wall -fPIC -I$(PERLCORE) -I. -c helloworld.c +-Wl,-rpath,. -o $@ clean : rm -f helloworld.o helloworld.c const-c.inc const-xs +.inc ppport.h clean-all : clean rm -f libhelloworld.so
-----------------------/tmp/prova2/helloworld/helloworld.xs-----------------------
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include <helloworld.h> #include "const-c.inc" #include "extlibs/myprint.h" //#include "extlibs/myprint.c" MODULE = helloworld PACKAGE = helloworld INCLUDE: const-xs.inc void helloworld_proc() CODE: printf ("Helloworld\n"); boxing_print ("Helloworld");
-----------------------/tmp/prova2/helloworld/helloworld.pm-----------------------
package helloworld; use 5.008007; use strict; use warnings; use Carp; require XSLoader; our $VERSION = '0.01'; XSLoader::load('helloworld', $VERSION); 1;
-----------------------/tmp/prova2/helloworld/extlibs/Makefile---------------------
# Makefile localpath=/tmp/prova2/helloworld/extlibs LD_RUN_PATH=$(localpath) CC=gcc .PHONY: clean clean-all all : libmyprint.so test myprint.o : myprint.c $(CC) -c myprint.c -Fpic -o $@ libmyprint.so : myprint.o myprint.h $(CC) -shared myprint.o -o $@ test : test.c $(CC) -Wall test.c -I$(localpath) -L$(localpath) -Wl +,-rpath,$(localpath) -lmyprint -o $@ clean : rm -f *.o clean-all : clean rm -f *.so test
-----------------------/tmp/prova2/helloworld/extlibs/myprint.c----------------------
#include "stdio.h" #include "string.h" #include "myprint.h" void boxing_print (char *st) { int t=0; for (t=0; t<strlen(st); t++) printf ("-"); printf ("\n%s\n", st); for (t=0; t<strlen(st); t++) printf ("-"); printf ("\n"); return; }
-----------------------/tmp/prova2/helloworld/extlibs/myprint.h-----------------------
void boxing_print (char*);
Thank you for your help. Best regards Warlock

In reply to shared-obj linking in xs-module by warlock

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.