编译包装器时出现SWIG [C++ to Lisp(CFFI)]错误

SWIG [C++ to Lisp(CFFI)] error when compiling wrapper

本文关键字:Lisp to CFFI 错误 C++ 包装 SWIG 编译      更新时间:2023-10-16

我是一个初学者,使用SWIG在C++和Lisp之间有接口。我已经遵循了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. 

有人可以帮助我吗?

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

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

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