in reply to Re^4: Why does the h2xs -x switch not generate XSUBs?
in thread Why does the h2xs -x switch not generate XSUBs?

All my compile switches are in the Makefile...

Of course they are :D ok, I can compile libtwintree with mingw(strawberryperl/win32), but it exports no symbols. So I end up with

TwinTree.o:TwinTree.c:(.text+0x29e): undefined reference to `return_on +e' TwinTree.o:TwinTree.c:(.text+0x3de): undefined reference to `return_ze +ro'

Your ldd output shows it isn't looking for libtwintree , so whatever is going on, its all c to me :)

All of this seems normal to me. Purpose of h2xs is for generating starting point, you have to do the c programming :)

Replies are listed 'Best First'.
Re^6: Why does the h2xs -x switch not generate XSUBs?
by FloydATC (Deacon) on Jul 24, 2009 at 13:13 UTC
    It's just that the XSUB code is supposed to make the actual call to the library, yes? As long as this is missing, the library could implement the meaning of life, universe and everything and the perl script would never know.

    And the thing is, even if I write the XSUB code manually, say for instance like this

    int return_one() CODE: RETVAL = return_one(); OUTPUT: RETVAL int return_zero() CODE: RETVAL = return_one(); OUTPUT: RETVAL
    ..it still doesn't work:
    PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/TwinTree....NOK 1 + # Failed test 'use TwinTree;' # at t/TwinTree.t line 9. # Tried to use 'TwinTree'. # Error: Can't load '/home/floyd/twintree/TwinTree/blib/arch/auto +/TwinTree/TwinTree.so' for module TwinTree: /home/floyd/twintree/Twin +Tree/blib/arch/auto/TwinTree/TwinTree.so: undefined symbol: return_on +e at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line +230. # at (eval 4) line 2 # Compilation failed in require at (eval 4) line 2. # BEGIN failed--compilation aborted at (eval 4) line 2. # Looks like you failed 1 test of 1. t/TwinTree....dubious + Test returned status 1 (wstat 256, 0x100) DIED. FAILED test 1 Failed 1/1 tests, 0.00% okay Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t/TwinTree.t 1 256 1 1 100.00% 1 Failed 1/1 test scripts, 0.00% okay. 1/1 subtests failed, 0.00% okay. make: *** [test_dynamic] Error 1
    ...the pieces just don't fit. There's probably just a tiny command-line switch or something missing somewhere, but I still don't have the faintest clue where to look. Logically I would expect h2xs to discover this and point it out, instead of generating a lot of code that just doesn't compile.
    -- Time flies when you don't know what you're doing
      It's just that the XSUB code is supposed to make the actual call to the library, yes?

      No. You're confused. h2xs just generates scaffolding. It doesn't compile code, it doesn't link code. It has nothing to do with the error. ldd shows you libtwintree isn't being loaded by TwinTree, probably because libtwintree exports nothing. You need to examine what the compiler/linker are doing before/during make.

        Thanks for clearing that up. I was expecting to see XSUB stuff looking like the examples in perlxstut but it seems those stubs are indeed sufficient for functions that don't involve passing anything fancy like structs or arrays.

        I finally got it to work by making two changes. (Irrelevant stuff trimmed)

        TwinTree.xs : libtwintree.so install mkdir -p TwinTree && \ cp libtwintree.h TwinTree && \ h2xs -Oxan TwinTree libtwintree.h -ltwintree # Removed "lib" ----------------------------^ libtwintree.so : libtwintree.o gcc -shared -o libtwintree.so libtwintree.o # Removed "-Wl,-soname,libtwintree.so" and "-lc"
        Again, thank you for putting up and pointing me in the right direction :-)

        -- Time flies when you don't know what you're doing