joec_ has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I'm trying to compile XML::LibXML::Common 0.13 on linux and when i try to 'make test' i get this error:

Can't load 'blib/arch/auto/XML/LibXML/Common/Common.so' for module XML +::LibXML::Common: blib/arch/auto/XML/LibXML/Common/Common.so: undefin +ed symbol: xmlFree at /apps/perl5.8.7/lib/5.8.7/i686-linux-thread-mul +ti/DynaLoader.pm line 230. at test.pl line 10 Compilation failed in require at test.pl line 10. BEGIN failed--compilation aborted at test.pl line 10. make: *** [test_dynamic] Error 2
Does anyone know what this means and how to solve it? I want to eventually install XML::LibXML.

Thanks in advance -- Joe

p.s. Why does make give me this output:

enable native perl UTF8 running xml2-config... ok looking for -lxml2... yes Checking if your kit is complete... Looks good Note (probably harmless): No library found for -lxml2 Writing Makefile for XML::LibXML::Common
It says it finds lxml2 but then contradicts itself. Im sure that this will cause future problems...

Thanks

-----

Eschew obfuscation, espouse elucidation!

Replies are listed 'Best First'.
Re: XML::LibXML::Common 0.13 on linux - undefined symbol
by nikosv (Deacon) on May 12, 2009 at 16:28 UTC
    Probably the symbol xmlFree is not defined in the Common.so library and is needed by the linking. try
    nm blib/arch/auto/XML/LibXML/Common/Common.so|grep 'xmlFree'
    and see if the symbol name comes up with that name or a bit altered;I have seen cases that the symbol name looked up contained an underscore;ie. the function name that was called by the programm was iiseterr and inside the library it was iiseterr_.The underscore did the damage and the symbol could not be found.This was resolved by editing the program and adding an underscore
      Hi

      This is the output of that command:
          U xmlFree

      What does this mean?

      Thanks

      -----

      Eschew obfuscation, espouse elucidation!

        It means that the library (Common.so) is using that symbol, but the symbol is undeclared ("U") within the library itself, i.e. it's an external reference that needs to be satisfied by some other library.

        The symbol is most likely expected to be defined in the shared library libxml2.so that Common.so is presumably linked against — that library contains the actual implementation of most of the functionality; Common.so is just the Perl/C wrapping code...  In other words, you could try to run "nm -D" on libxml2 to see if the symbol is defined there  (check the build output for where the lib was found). The symbol should not be listed as "U" there, but rather as something like "T" ("text" section, aka code), or "D" ("data" section).

        Update: just checked on my box with v2.6.32 and an older box with v2.6.31, and the symbol is defined (in both cases):

        $ nm -D /usr/lib/libxml2.so.2.6.32 | grep xmlFree\$ 000000000035a6c0 D xmlFree
Re: XML::LibXML::Common 0.13 on linux - undefined symbol
by syphilis (Archbishop) on May 12, 2009 at 23:08 UTC
    It says it finds lxml2 but then contradicts itself. Im sure that this will cause future problems...

    I think so, too - in fact, it's probably the cause of the *present* problem.
    When MakeMaker says Note (probably harmless): No library found for -lxml2 that means that MakeMaker is not going to pass that -lxml2 link along, so no attempt will be made to link to libxml2.a. Assuming that libxml2.a is the name of your xml2 import library, the absence of that link is the likely cause of the error you see.

    I would replace the existing Makefile.PL with:
    use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'XML::LibXML::Common', 'VERSION_FROM' => 'Common.pm', # finds $VERSION 'AUTHOR' => 'Christian Glahn <christian.glahn@uibk.ac.at>', 'ABSTRACT' => 'Routines and Constants common for XML::LibXML +and XML::GDOME', 'LIBS' => '-lxml2', );
    UPDATE: Added the LIBS parameter to the above proposed Makefile.PL.

    And then, if the libxml2 library and headers are not in a location where they will be found by default, start with:
    perl Makefile.PL INC="-I/path/to/xml_headers" LIBS="-L/path/to/xml_lib + -lxml2"
    Otherwise just start with perl Makefile.PL as normal. (Again, I've assumed that 'libxml2.a' is the name of the library that needs to be found.)

    That approach worked fine for me recently.

    Cheers,
    Rob
      I've assumed that 'libxml2.a' is the name of the library that needs to be found.

      Actually, when you specify -lxml2 on the compiler/linker command line, gcc will happily use either a static (.a) or a shared lib (.so).  In fact it even defaults to using the shared lib when both a .a and .so file are found.

      In other words, as there usually is a shared lib available these days (when the library is installed at all), linking will happen against that shared one, unless you take special precautions (like explicitly requesting static linking, or temporarily moving away the shared lib, or specifying the full path to the .a file directly instead of -lxml2).

        gcc will happily use either a static (.a) or a shared lib (.so)

        Yes - thanks for correcting that. (On Win32, gcc is also capable of linking to the dll.)
        One difficulty in trying to solve the op's problem is that I don't know the name of the file that needs to be linked in. The point I was trying to make was that, if the linking to that file is achieved with '-lxml2', then the linking won't take place, simply because MakeMaker has removed that '-lxml2' link.

        Cheers,
        Rob
Re: XML::LibXML::Common 0.13 on linux - undefined symbol
by nikosv (Deacon) on May 14, 2009 at 10:57 UTC