C++ swigperl:错误的ELF类
我正在尝试使用Swig从CXX模块构建一个Perl模块。 有多个与此相关的指南:C++ swigperl:错误的ELF类,c++,perl,swig,elf,C++,Perl,Swig,Elf,我正在尝试使用Swig从CXX模块构建一个Perl模块。 有多个与此相关的指南: 泛型函数包含一个Perl部分 向导 向导 我是Swig新手,对C(++)不是很熟悉,但我能够按照中的教程编译我的模块: 我创建了一个接口文件: %module my_module %{ #include "case.h" #include "case.h" #include "lexindex.h" #include "intlist.h" #include "weight
%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();
};
我运行Swig:
swig -c++ -perl5 my_module.i
这将生成文件my\u module\u wrap.cxx
。
我汇编:
g++ -c `perl -MConfig -e 'print join(" ", @Config{qw(ccflags optimize cccdlflags)}, "-I$Config{archlib}/CORE")'` my_module.cxx my_module_wrap.cxx
随后:
g++ `perl -MConfig -e 'print $Config{lddlflags}'` my_module.o my_module_wrap.o -o my_module.so
正如预期的那样,这确实创建了文件my\u模块
然后我试着这样使用它:
$ perl
use my_module;
这将导致以下错误:
无法在/usr/net/ActivePerl-5.14.2.1402/lib/DynaLoader.pm第191行为模块my_module:./my_module.so:加载错误的ELF类:ELFCLASS64
从错误消息中可以看到,我使用ActivePerlV5.14。
根据文档,Swig应该支持Perl版本>=5.8。否则,我看不出哪里可以挖得更深
存在一个错误,但这是使用不同Python解释器的用户错误
Can't load './my_module.so' for module my_module: ./my_module.so: wrong ELF class: ELFCLASS64
这意味着:您正在尝试将64位my_模块加载到32位perl
进程中
您必须使用64位perl
,或者将my_模块重新构建为32位共享库(通过添加-m32
来编译和链接命令)。您不应该一次问多个问题,特别是在评论部分。我无法复制说明,因为缺少文件my_module.cxx
。您可能必须将当前目录添加到共享库搜索路径。试着像这样运行perl
:$LD\u LIBRARY\u PATH=。perl
。有关示例,请参见。。