问题
I am trying to build a Perl module out of a CXX module using Swig. There are multiple guides related to this:
- The generic Swig tutorial with a Perl section
- The Swig and C++ guide
- The Swig and Perl5 guide
I'm new to Swig and not very familiar with C(++), but I've been able to compile my module following the tutorial in 1:
I created an interface file:
%module my_module
%{
#include "case.h"
#include "case.h"
#include "lexindex.h"
#include "intlist.h"
#include "weight.h"
#include "invindex.h"
#include "winnow.h"
#include "nbayes.h"
#include "svmclass.h"
#include "svm.h"
#include "sockhelp.h"
#include "strtok_r.h"
extern int num_features_guess;
void StopServerFun( int Signal );
%}
extern int num_features_guess;
class Case {
public:
Case();
~Case();
};
class Feature {
public:
Feature();
~Feature();
};
I run Swig:
swig -c++ -perl5 my_module.i
This generates the file my_module_wrap.cxx
.
I compile:
g++ -c `perl -MConfig -e 'print join(" ", @Config{qw(ccflags optimize cccdlflags)}, "-I$Config{archlib}/CORE")'` my_module.cxx my_module_wrap.cxx
And subsequently:
g++ `perl -MConfig -e 'print $Config{lddlflags}'` my_module.o my_module_wrap.o -o my_module.so
As expected, this does create the file my_module.so
.
Then I try to use it like this:
$ perl
use my_module;
This results in the following error:
Can't load './my_module.so' for module my_module: ./my_module.so: wrong ELF class: ELFCLASS64 at /usr/net/ActivePerl-5.14.2.1402/lib/DynaLoader.pm line 191.
As you can see from the error message, I use ActivePerl v5.14. According to the documentation, Swig should support Perl version >=5.8. Otherwise, I do not see where to dig deeper.
There is a similar question about Python, but this was a user fault using different Python interpreters.
回答1:
Can't load './my_module.so' for module my_module: ./my_module.so: wrong ELF class: ELFCLASS64
This means: you are trying to load 64-bit my_module.so
into a 32-bit perl
process.
You must either use 64-bit perl
, or rebuild my_module.so
as a 32-bit shared library (by adding -m32
to compile and link commands).
来源:https://stackoverflow.com/questions/51382757/swig-perl-wrong-elf-class