【问题标题】:Create C++ interface for perl using SWIG?使用 SWIG 为 perl 创建 C++ 接口?
【发布时间】:2016-01-30 19:18:56
【问题描述】:

我正在尝试掌握 SWIG。现在,我无法为 perl 构建简单的模块。这是我所做的:

example.cpp:

#include <iostream>

void hello()
{
    std::cout << "Hello, world!"<< std::endl;
}

example.i:

%module example
%{
#include <iostream>
extern void hello();
%}

extern void hello();

app.pl:

#!/usr/bin/perl

use strict;
use warnings;

use example;

example::hello();

还有我的compile.sh 脚本:

#!/bin/bash -ex

arch=`perl -e 'use Config; print $Config{archlib};'`    

swig3.0 -c++ -perl5 example.i
g++ -fPIC -c example.cpp
g++ -fPIC -c example_wrap.cxx -I$arch/CORE -L$arch/CORE
g++ -shared example_wrap.o -o example.so

编译正常 - 没有显示错误。但是,当我运行 app.pl 时,出现以下错误:

/usr/bin/perl: symbol lookup error: ./example.so: undefined symbol: _Z5hellov

我尝试谷歌了一下,但无济于事。到目前为止,一切都失败了。我做错了什么?

我正在使用带有 3.13 内核和 perl 5.18.2 的 Linux Ubuntu x86_64

【问题讨论】:

    标签: c++ linux perl swig


    【解决方案1】:

    看看小休息的力量。

    原因很简单:我没有在编译链中添加example.o - 所以确实没有定义 hello() 函数!

    为了解决这个问题,我将 compile.sh 最后一行更改为: g++ -shared example.o example_wrap.o -o example.so

    我觉得自己很愚蠢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      相关资源
      最近更新 更多