【发布时间】:2018-07-17 13:33:46
【问题描述】:
我正在尝试使用 Swig 从 CXX 模块构建 Perl 模块。 有多个与此相关的指南:
- 带有 Perl 部分的通用 Swig tutorial
- Swig and C++ 指南
- 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 解释器的用户错误。
【问题讨论】:
-
你不应该一次问多个问题,尤其是在 cmets 部分。
-
我无法复制说明,因为文件
my_module.cxx丢失。 -
您可能需要将当前目录添加到共享库搜索路径。尝试像这样运行
perl:$ LD_LIBRARY_PATH=. perl。有关示例,请参阅SWIG: Wrapping C++ for Perl using only a header and a shared library, can't locate loadable object error..