gpt4 book ai didi

c++ - 痛饮 Perl : wrong ELF class

转载 作者:行者123 更新时间:2023-11-28 04:36:12 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com