Dear Monks,

I have two C++ library files that do the same thing in 32bit and 64bit. Libconf.so for 32 bit executable file and libconf64.so for 64 bit executable file. I tried to load the library file dynamically by using of 'DynaLoader' module.

While I tried the load the libconf64.so file to perl 5.8.8 64bit in linux RedHat 64 bit machine. It ran successfully and able to call some function in the libconf64.so file. I tried the same script in to load the libconf.so file to perl 5.8.8 32bit in linux RedHat 32bit machine. It able load the libconf.so file, but while I call some function in the library file, it gives the 'Segmentation fault' error. Below i place the sample code what i tried the 64 bit macine and 32bit machine. Please suggest me how to rectify the error.

Sample code

use DynaLoader; # declare the library functions @exconfig_syms = ('XS_ExConfig_fnGetLocalIPAddresses'); # declare the library files $ExConfigLibFile='libconf.so'; # load the library file $exconfig_libref = load_shared_lib($ExConfigLibFile); unless (import_shared_lib_syms($exconfig_libref, \@exconfig_syms)) { print ("\n*** ERROR: failed to import symbols from library '$ExCon +figLibFile'!"); exit; } { my @locals = split(/\|/, hostIP()); print ("Local address". ((@locals > 1) ? "es" : '').":\n\t" . join + ("\n\t", @locals)); } sub load_shared_lib { my $lib_file = shift; my $lib_ref = undef; $lib_ref = DynaLoader::dl_load_file($lib_file,1); return $lib_ref; } sub import_shared_lib_syms { my $lib_ref = shift; my $lib_syms = shift; # Load functions from shared library foreach my $key (@{$lib_syms}) {#Load function from shared library my $sym_ref = DynaLoader::dl_find_symbol($lib_ref, $key); unless ($sym_ref) { print("\nCan't load symbol '$key' from shared library $lib_fil +e:\n\t". DynaLoader::dl_error()); return 0; } # Install XSub function (my $func = $key) =~ s/XS_//; my $func_ref = DynaLoader::dl_install_xsub($func, $sym_ref); unless ($func_ref) { print("\nUnable to install '$key' function from shared library + $lib_file:\n\t". DynaLoader::dl_error()); return 0; } } return 1; # $lib_ref; } sub hostIP { my $IPs; # the below functon return the value in 64bit perl # and it returns the 'Segmentation fault' error in 32bit perl ExConfig_fnGetLocalIPAddresses($IPs); return $IPs; }

In reply to Segmentation fault error in 32bit machine by k_manimuthu

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.