【问题标题】:Swig Perl: wrong ELF classSwig Perl:错误的 ELF 类
【发布时间】:2018-07-17 13:33:46
【问题描述】:

我正在尝试使用 Swig 从 CXX 模块构建 Perl 模块。 有多个与此相关的指南:

  1. 带有 Perl 部分的通用 Swig tutorial
  2. Swig and C++ 指南
  3. Swig and Perl5 指南

我是 Swig 的新手,对 C(++) 不是很熟悉,但我已经能够按照 1 中的教程编译我的模块:

我创建了一个接口文件:

%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_module_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_module.so

然后我尝试像这样使用它:

$ perl
use my_module;

这会导致以下错误:

无法为模块 my_module 加载“./my_module.so”:./my_module.so:错误的 ELF 类:ELFCLASS64 位于 /usr/net/ActivePerl-5.14.2.1402/lib/DynaLoader.pm 第 191 行。

从错误消息中可以看出,我使用的是 ActivePerl v5.14。 根据文档,Swig 应该支持 Perl 版本 >=5.8。否则,我看不出哪里可以深入挖掘。

有一个similar question about Python,但这是使用不同 Python 解释器的用户错误。

【问题讨论】:

标签: c++ perl swig elf


【解决方案1】:
Can't load './my_module.so' for module my_module: ./my_module.so: wrong ELF class: ELFCLASS64 

这意味着:您正在尝试将 64 位 my_module.so 加载到 32 位 perl 进程中。

您必须使用 64 位 perl,或将 my_module.so 重建为 32 位共享库(通过添加 -m32 来编译和链接命令)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-04
    • 2016-11-25
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 2022-08-17
    • 2013-09-05
    • 2012-08-19
    相关资源
    最近更新 更多