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

Hi Gurus, I want to create a perl module that uses a shared library (that I wrote). In order to use this *.so (that by the way is working fine with another exe) in my pm, I changed the *pm file. that *.pm file was created using h2xs -AXc -n NewModule. so after my change the pm file (lib/cNewModule.pm) contains the following declaration : use Inline CPP => Config => LIBS => "-L/users/nirf/perlTrials/cNewModule/lib/ -lmain"; in the folder /users/nirf/perlTrials/cNewModule/lib/ I have libmain.so. (and I even tried to add this path into LD_LIBRARY_PATH to make things work) However,when I test the module, the "make test" keeps telling me that it has undefined symbols. Meaning that it can't load/link libmain.so. does any of you has any idea of what is wrong or what else should I check ? Thanks, Nir

Replies are listed 'Best First'.
Re: Inline CPP
by moritz (Cardinal) on May 20, 2008 at 09:54 UTC
    So you didn't heed our various advices from this tread. You're again not formatting your posts properly, making them very hard to read.

    And yet you still hope that opening a new thread will magically get you better responses, even though refuse to answer some of our questions?

    If you don't understand an answer, ask. But don't open a new thread without referencing the old one. We're not stupid, we will notice.

      Hi Morits, First of all I am sorry that I didn't wrap the error message before (with code). Second of all I didn't see that Rob answered me until you mentioned it. and third, eveuntually I managed to fix those mysterious errors I had (in the my previous published thread) by starting a new pm file from a sample I found under math folder in inline. This thread is not an attempt to mislead you or something of that kind, and I am sorry that this is the impression that was created. This thread is attempting to solve other problems - namely Linking problems I have when using Inline. I will insert the error message again:
      PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/cNewModule....ok 1/1Had problems bootstrapping Inline module 'cNewMo +dule_061a' Can't load '/users/nirf/perlTrials/cNewModule/_Inline/lib/auto/cNewMod +ule_061a/cNewModule_061a.so' for module cNewModule_061a: /users/nirf/ +perlTrials/cNewModule/_Inline/lib/auto/cNewModule_061a/cNewModule_061 +a.so: undefined symbol: _ZN7MyClassC1EPKc at /usr/lib/perl5/5.8.5/i38 +6-linux-thread-multi/DynaLoader.pm line 230. at /users/nirf/perlTrials/cpanModulesInstallationInline/lib/perl5/sit +e_perl/5.8.5/Inline.pm line 500 at t/cNewModule.t line 0 INIT failed--call queue aborted. # Looks like your test died just after 1. t/cNewModule....dubious Test returned status 255 (wstat 65280, 0xff00) after all the subtests completed successfully Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t/cNewModule.t 255 65280 1 0 0.00% ?? Failed 1/1 test scripts, 0.00% okay. 0/1 subtests failed, 100.00% okay +. make: *** [test_dynamic] Error 2
      Thanks, Nir
Re: Inline CPP
by Anonymous Monk on May 20, 2008 at 09:44 UTC
    Start with with exact error messages
      Hi again The error message is
      PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/cNewModule....ok 1/1Had problems bootstrapping Inline module 'cNewMo +dule_061a' Can't load '/users/nirf/perlTrials/cNewModule/_Inline/lib/auto/cNewMod +ule_061a/cNewModule_061a.so' for module cNewModule_061a: /users/nirf/ +perlTrials/cNewModule/_Inline/lib/auto/cNewModule_061a/cNewModule_061 +a.so: undefined symbol: _ZN7MyClassC1EPKc at /usr/lib/perl5/5.8.5/i38 +6-linux-thread-multi/DynaLoader.pm line 230. at /users/nirf/perlTrials/cpanModulesInstallationInline/lib/perl5/sit +e_perl/5.8.5/Inline.pm line 500 at t/cNewModule.t line 0 INIT failed--call queue aborted. # Looks like your test died just after 1. t/cNewModule....dubious Test returned status 255 (wstat 65280, 0xff00) after all the subtests completed successfully Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t/cNewModule.t 255 65280 1 0 0.00% ?? Failed 1/1 test scripts, 0.00% okay. 0/1 subtests failed, 100.00% okay +. make: *** [test_dynamic] Error 2
      Thanks, Nir
Re: Inline CPP
by syphilis (Archbishop) on May 21, 2008 at 07:47 UTC
    Were there any other errors during the build ?

    It's important that you also:
    use Inline CPP => Config => BUILD_NOISY => 1;
    Then check the entire output of the build for a message something like (if not exactly):
    Note (probably harmless): No library found for -lmain
    There are 2 possibilities:
    1)If that message is present, then no attempt was made to link to libmain.so.
    2)If the message is absent, then libmain.so was found and linked to.

    If it's a case of 1), then we need to work out why it was not locatable.

    If it's a case of 2), then we need to work out why libmain.so does not resolve that symbol.

    Which is it ?

    Update: If you decide to add the BUILD_NOISY => 1 config option and re-run the build process again, you'll probably find that it will just use the existing binaries and not compile again - which would be a pointless exercise. So, before rebuilding, remove the existing _Inline/build files for that particular module. (Or add some whitespace to the CPP code ... as long as you do something to make it recompile the CPP code.)

    Cheers,
    Rob
      Hi Rob, You are most helpfull and I really appreciate your help. I did as you said : 1. I "make clean" to erase all the compiled objects. 2. I added your BUILD_NOISY flag. 3. I addid a -L directive to the loaction of that lib in a different style (all the directive together seems to work better than separately - I don't know why):
      use Inline (CPP => 'DATA', LIBS => '-L/users/nirf/perlTrials/cNewModule/lib -lmai +n -L/usr/lib -lstdc++', INC => '-I/users/nirf/perlTrials/inlineExample', WARNINGS => 0, NAME => 'PM_wed', VERSION => '0.01', BUILD_NOISY => 1, );
      4.I tried to remove the warnings regarding iostream.h by adding to the parameters the line " ENABLE => STD_IOSTREAM," :
      use Inline (CPP => 'DATA', LIBS => '-L/users/nirf/perlTrials/cNewModule/lib -lmai +n -L/usr/lib -lstdc++', INC => '-I/users/nirf/perlTrials/inlineExample', WARNINGS => 0, NAME => 'PM_wed', VERSION => '0.01', BUILD_NOISY => 1, ENABLE => STD_IOSTREAM, );
      but it didn't work. do you know why? 5.The new error I get now is as follows. It doesn't find that library (although it says so only in the test phase):
      PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/1....ok 1/1Had problems bootstrapping Inline module 'PM_wed' Can't load '/users/nirf/perlTrials/PM_wed/blib/arch/auto/PM_wed/PM_wed +.so' for module PM_wed: libmain.so: cannot open shared object file: N +o such file or directory at /usr/lib/perl5/5.8.5/i386-linux-thread-mu +lti/DynaLoader.pm line 230, <DATA> line 1. at /usr/lib/perl5/vendor_perl/5.8.5/Inline.pm line 500 at t/1.t line 0 INIT failed--call queue aborted, <DATA> line 1. # Looks like your test died just after 1. t/1....dubious Test returned status 255 (wstat 65280, 0xff00) after all the subtests completed successfully Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t/1.t 255 65280 1 0 0.00% ?? Failed 1/1 test scripts, 0.00% okay. 0/1 subtests failed, 100.00% okay +. make: *** [test_dynamic] Error 2
      By the way,the messages I get in the "make" phase seems ok (there is no indication to the error that follows at the next "test" phase) :
      cp PM_wed.pm blib/lib/PM_wed.pm /usr/bin/perl -Mblib -MInline=NOISY,_INSTALL_ -MPM_wed -e1 0.01 blib/a +rch Starting Build Prepocess Stage Finished Build Prepocess Stage Starting Build Parse Stage Finished Build Parse Stage Starting Build Glue 1 Stage Finished Build Glue 1 Stage Starting Build Glue 2 Stage Finished Build Glue 2 Stage Starting Build Glue 3 Stage Finished Build Glue 3 Stage Starting Build Compile Stage Starting "perl Makefile.PL" Stage WARNING: CC is not a known parameter. Writing Makefile for PM_wed Finished "perl Makefile.PL" Stage Starting "make" Stage make[1]: Entering directory `/users/nirf/perlTrials/PM_wed/_Inline/bui +ld/PM_wed' /usr/bin/perl /usr/lib/perl5/5.8.0/ExtUtils/xsubpp -typemap /usr/lib/ +perl5/5.8.0/ExtUtils/typemap PM_wed.xs > PM_wed.xsc && mv PM_wed.xs +c PM_wed.c g++ -c -I/users/nirf/perlTrials/PM_wed -I/users/nirf/perlTrials/inlin +eExample -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING - +fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_ +OFFSET_BITS=64 -I/usr/include/gdbm -O2 -march=i386 -mcpu=i686 -g -D +VERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC "-I/usr/lib/perl5/5.8.0/ +i386-linux-thread-multi/CORE" PM_wed.c In file included from /usr/include/c++/3.2.2/backward/iostream.h:31, from PM_wed.xs:2: /usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #war +ning This file includes at least one deprecated or antiquated header. + Please consider using one of the 32 headers found in section 17.4.1. +2 of the C++ standard. Examples include substituting the <X> header f +or the <X.h> header for C++ includes, or <sstream> instead of the dep +recated header <strstream.h>. To disable this warning use -Wno-deprec +ated. Running Mkbootstrap for PM_wed () chmod 644 PM_wed.bs rm -f blib/arch/auto/PM_wed/PM_wed.so LD_RUN_PATH="/usr/lib:/users/nirf/perlTrials/cNewModule/lib" gcc -sha +red -L/usr/local/lib PM_wed.o -o blib/arch/auto/PM_wed/PM_wed.so - +lstdc++ -L/users/nirf/perlTrials/cNewModule/lib -lmain -L/usr/lib -ls +tdc++ chmod 755 blib/arch/auto/PM_wed/PM_wed.so cp PM_wed.bs blib/arch/auto/PM_wed/PM_wed.bs chmod 644 blib/arch/auto/PM_wed/PM_wed.bs make[1]: Leaving directory `/users/nirf/perlTrials/PM_wed/_Inline/buil +d/PM_wed' Finished "make" Stage Starting "make install" Stage make[1]: Entering directory `/users/nirf/perlTrials/PM_wed/_Inline/bui +ld/PM_wed' Installing /users/nirf/perlTrials/PM_wed/blib/arch/auto/PM_wed/PM_wed. +so Installing /users/nirf/perlTrials/PM_wed/blib/arch/auto/PM_wed/PM_wed. +bs Files found in blib/arch: installing files in blib/lib into architectu +re dependent library tree Writing /users/nirf/perlTrials/PM_wed/blib/arch/auto/PM_wed/.packlist make[1]: Leaving directory `/users/nirf/perlTrials/PM_wed/_Inline/buil +d/PM_wed' Finished "make install" Stage Starting Cleaning Up Stage Finished Cleaning Up Stage Finished Build Compile Stage
      Thanks, Nir
        Hi Rob, I managed to solve the linkage problem. I still have the problem with ENABLE => STD_IOSTREAM - I still need help in that aspect). Apparently in the test phase The LD_LIBRARY_PATH should have the path to the libmain.so (my external libraries). and it is not sufficient to have that path in the pm file (in the LIBS -L option in
        use Inline (CPP => 'DATA', LIBS => '-L/users/nirf/perlTrials/cNewModule/lib -lmai +n -L/usr/lib -lstdc++', INC => '-I/users/nirf/perlTrials/inlineExample', WARNINGS => 0, NAME => 'PM_wed', VERSION => '0.01', BUILD_NOISY => 1, );
        ) Thanks, Nir