c++ - 痛饮 Perl : wrong ELF class

标签 c++ perl swig elf

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

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

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

我创建了一个接口(interface)文件:

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

这会导致以下错误:

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.

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

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

最佳答案

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编译和链接命令)。

关于c++ - 痛饮 Perl : wrong ELF class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51382757/

相关文章:

c++ - Boost echo 服务器示例并在 lambda 中捕获 this 和 shared_from_this()

c++ - 在套接字中发送/接收之间同步

c++ - 视觉 C++ : Unable to invoke method from another class

perl - `die` 时如何判断行号?

perl - IO::Socket 与 Socket 我都是 "use"吗?

python - 将 ctypes int** 转换为 numpy 二维数组

c++ - 已部署的 C++ AMP 应用程序停止响应

perl - 是否可以在 emacs 中突出显示内插的 perl 变量?

python - python 导演使用的 swig 错误 c++

c++ - 动态链接和 Python SWIG (C++) 在 C++ 中工作在 python 中失败