Hello! I want tu reuse existing c code from different c files. I neither have them as a real library, nor would I like to copy+paste them into my Perl module (after the __C__ tag). The reason for that is, that the original c code comes from an open source project of a standalone program (gnubg). I just don't want to reinvent the wheel and still be flexible enough for oncoming future versions of the program.
Is there a trick or a common known problem how to use normal c files via #include "file.h" with Inlince::C. I only found examples where some libraries like ncurses, gtk or similar were used. That was solved with the LIB => -L .... option, but that seems different to including "simple" c files (sorry if it's the wrong expression, I'm not a good c programmer). Here's a voluminous description of what I've tried. I started the module with the normal stuff and the use Inline part: use Inline C => 'DATA', NAME => 'Games::Backgammon', VERSION => '0.03'; and after the Perl lines the C part comes: __DATA__ __C__ #include <errno.h> #include "positionid.h" int _CheckPosition(AV* a) { int i, j; int anBoard[ 2 ][ 25 ]; for (i = 0; i < 2; i++) { for (j = 0; j < 25; j++) { SV** sv = av_fetch(a,25*i + j,0); anBoard[ i ][ j ] = SvIV(*sv); } } return CheckPosition(anBoard) == 0; } } As you can see, it's only a simple (O.K. ineffective, but that's not my problem) wrapper that delegates to the CheckPosition method from positionid.[cho]. I first copied the position.* files to the same directory where also the Perl module is. That resulted in a problem with make (allthough in Makefile.PL the module had been changed to Inline::MakeMaker), as it now tried to find Backgammon.o ?! cp Backgammon.pm blib/lib/Games/Backgammon.pm Running Mkbootstrap for Games::Backgammon () chmod 644 Backgammon.bs rm -f blib/arch/auto/Games/Backgammon/Backgammon.so LD_RUN_PATH="" cc -shared -L/usr/local/lib Backgammon.o -o blib/arch/auto/Games/Backgammon/Backgammon.so cc: Backgammon.o: Datei oder Verzeichnis nicht gefunden cc: no input files make: *** [blib/arch/auto/Games/Backgammon/Backgammon.so] Fehler 1 When I deleted these files (known that now of course it would be impossible to find a position.h or even the .c or .o file), at least make called the Inline module. Starting Build Prepocess Stage Finished Build Prepocess Stage [snipped some uninteresting stuff] cc1: warning: changing search order for system directory "/usr/local/include" cc1: warning: as it has already been specified as a non-system directory Backgammon.xs:7:24: positionid.h: Datei oder Verzeichnis nicht gefunden make[1]: *** [Backgammon.o] Fehler 1 make[1]: Verlassen des Verzeichnisses Verzeichnis »/home/janek/projects/Games-Backgammon/_Inline/build/Games/Backgammon« [...] As expected, it also didn't worked. Now i created a subdirectory 'gnubg' where the positionid.* files are in. I also changed a parameter of use Inlines, that it can find gnubg: use Inline C => 'DATA', INC => '-I../../../../gnubg', NAME => 'Games::Backgammon', VERSION => '0.03'; The result was now, that make run without serious errors: [snipped ...] Starting "make" Stage make[1]: Wechsel in das Verzeichnis Verzeichnis »/home/janek/projects/Games-Backgammon/_Inline/build/Games/Backgammon« /usr/bin/perl /usr/lib/perl5/5.8.0/ExtUtils/xsubpp -typemap /usr/lib/perl5/5.8.0/ExtUtils/typemap Backgammon.xs > Backgammon.xsc && mv Backgammon.xsc Backgammon.c cc -c -I/home/janek/projects/Games-Backgammon -I../../../../gnubg -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -DVERSION=\"0.03\" -DXS_VERSION=\"0.03\" -fpic "-I/usr/lib/perl5/5.8.0/i686-linux-thread-multi/CORE" Backgammon.c cc1: warning: changing search order for system directory "/usr/local/include" cc1: warning: as it has already been specified as a non-system directory Running Mkbootstrap for Games::Backgammon () chmod 644 Backgammon.bs rm -f blib/arch/auto/Games/Backgammon/Backgammon.so LD_RUN_PATH="" cc -shared -L/usr/local/lib Backgammon.o -o blib/arch/auto/Games/Backgammon/Backgammon.so chmod 755 blib/arch/auto/Games/Backgammon/Backgammon.so cp Backgammon.bs blib/arch/auto/Games/Backgammon/Backgammon.bs chmod 644 blib/arch/auto/Games/Backgammon/Backgammon.bs make[1]: Verlassen des Verzeichnisses Verzeichnis »/home/janek/projects/Games-Backgammon/_Inline/build/Games/Backgammon« Finished "make" Stage Starting "make install" Stage make[1]: Wechsel in das Verzeichnis Verzeichnis »/home/janek/projects/Games-Backgammon/_Inline/build/Games/Backgammon« Installing /home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/Backgammon.so Installing /home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/Backgammon.bs Files found in blib/arch: installing files in blib/lib into architecture dependent library tree Writing /home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/.packlist make[1]: Verlassen des Verzeichnisses Verzeichnis »/home/janek/projects/Games-Backgammon/_Inline/build/Games/Backgammon« Finished "make install" Stage Starting Cleaning Up Stage Finished Cleaning Up Stage Finished Build Compile Stage Manifying blib/man3/Games::Backgammon.3 So far, so well. But now I tried to run my testscript with make test and could see that it didn't run: PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/1...............Had problems bootstrapping Inline module 'Games::Backgammon' Can't load '/home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/Backgammon.so' for module Games::Backgammon: /home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/Backgammon.so: undefined symbol: CheckPosition at /usr/lib/perl5/5.8.0/i686-linux-thread-multi/DynaLoader.pm line 237, <DATA> line 1. at /usr/lib/perl5/site_perl/5.8.0/Inline.pm line 500 at t/1.t line 0 INIT failed--call queue aborted, <DATA> line 1. t/1...............dubious Test returned status 255 (wstat 65280, 0xff00) DIED. FAILED test 1 Failed 1/1 tests, 0.00% okay t/set_position....Had problems bootstrapping Inline module 'Games::Backgammon' Can't load '/home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/Backgammon.so' for module Games::Backgammon: /home/janek/projects/Games-Backgammon/blib/arch/auto/Games/Backgammon/Backgammon.so: undefined symbol: CheckPosition at /usr/lib/perl5/5.8.0/i686-linux-thread-multi/DynaLoader.pm line 237, <DATA> line 1. at /usr/lib/perl5/site_perl/5.8.0/Inline.pm line 500 at t/set_position.t line 0 INIT failed--call queue aborted, <DATA> line 1. # No tests run! t/set_position....dubious Test returned status 255 (wstat 65280, 0xff00) DIED. FAILED tests 1-183 Failed 183/183 tests, 0.00% okay Failed Test Stat Wstat Total Fail Failed List of Failed ------------------------------------------------------------------------------- t/1.t 255 65280 1 1 100.00% 1 t/set_position.t 255 65280 183 183 100.00% 1-183 Failed 2/2 test scripts, 0.00% okay. 184/184 subtests failed, 0.00% okay. make: *** [test_dynamic] Fehler 2 I also tried to link it static, to copy the positionid.* files to other places, but it didn't help. Of course, I can do it with the classical XS style, but I would really prefer to use the nice Inline style! Thanks in advance, Janek