I'm a beginner with interface between C++ and Lisp with SWIG. I've follow the SWIG's documentation but I'm facing a problem. Here is the simple program I want to interface (It can easily be done in Lisp but it is to understand how to import C++ code into 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);
In order to use SWIG, I create the interface file:
test.i:
%module test
%include <test.hpp>
And, I've execute the following command line:
$ swig -c++ -cffi test.i
$ c++ -c test_wrap.cxx
But when compiling the test_wrap.cxx, the terminal says:
test_wrap.cxx:193:19: error: use of undeclared identifier 'test'
result = (int)test(arg1,arg2);
^
1 error generated.
Anyone can help me with that?
Here is a modified test.i
which makes the rest compile:
%module test
%{
#include "test.hpp"
%}
%include <test.hpp>
I followed this presentation (page 24) and apparently you need to insert the include
directive in the generated wrapper.