4

我是 C++ 和 Lisp 与 SWIG 之间接口的初学者。我已经按照 SWIG 的文档进行操作,但我遇到了问题。这是我想要接口的简单程序(它可以在 Lisp 中轻松完成,但它是为了了解如何将 C++ 代码导入 Lisp):

测试.cpp:

#include "test.hpp"
int test(int x, int y) {
   std::cout << x+y;
   return 0;
}

测试.hpp:

#include <iostream>
int test(int x, int y);

为了使用 SWIG,我创建了接口文件:

测试.i:

%module test
%include <test.hpp>

而且,我执行了以下命令行:

$ swig -c++ -cffi test.i 
$ c++ -c test_wrap.cxx

但是在编译 test_wrap.cxx 时,终端会说:

test_wrap.cxx:193:19: error: use of undeclared identifier 'test'
result = (int)test(arg1,arg2);
              ^
1 error generated. 

任何人都可以帮助我吗?

4

1 回答 1

3

这是一个test.i使其余部分编译的修改:

%module test
%{
#include "test.hpp"
%}

%include <test.hpp>

我遵循了这个演示文稿(第 24 页),显然您需要include在生成的包装器中插入指令。

于 2016-02-17T19:09:58.687 回答