我是使用SWIG在C++和Lisp之间进行接口(interface)的初学者。我已经阅读了SWIG的文档,但遇到了问题。
这是我要连接的简单程序(可以在Lisp中轻松完成,但要了解如何将C++代码导入Lisp):

test.cpp:

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

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

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

test.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.

有人可以帮我吗?

最佳答案

这是修改后的test.i,可以编译其余代码:

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

%include <test.hpp>

我遵循了this presentation(第24页),显然您需要在生成的包装器中插入include指令。

关于c++ - 编译包装程序时出现SWIG [C++至Lisp(CFFI)]错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35462435/

10-11 23:07
查看更多