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 | |
by k_manimuthu (Monk) on Apr 09, 2011 at 08:28 UTC |