Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Segmentation fault error in 32bit machine

by k_manimuthu (Monk)
on Apr 08, 2011 at 09:18 UTC ( [id://898300]=perlquestion: print w/replies, xml ) Need Help??

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

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; }

Replies are listed 'Best First'.
Re: Segmentation fault error in 32bit machine
by fidesachates (Monk) on Apr 08, 2011 at 13:03 UTC
    I'm unaware as to your knowledge of C, so this may be things you already know. Basically a seg fault occurs in a C program has a memory access violation. A good example is accessing the 11th element in an array that was only declared to have 10 elements.

    A seg fault occurs under many circumstances, but the most popular ones are:
    1. faulty programming 2. missing dependencies 3. faulty hardware 4. incorrect enviroment

    This doesn't sound like a perl problem, but more like something you should ask the authors of the file.

      Now i am trying to debug the binary files by using of GDB and valgrind. Yes, the binary files having some issues.
      Thanks for your information.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://898300]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found