4

私は SWIG を使用した C++ と Lisp の間のインターフェースの初心者です。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 を使用するために、インターフェイス ファイルを作成します。

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. 

誰でもそれで私を助けることができますか?

4

1 に答える 1

3

test.i残りをコンパイルする変更は次のとおりです。

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

%include <test.hpp>

このプレゼンテーション(page 24)に従いincludeましたが、生成されたラッパーにディレクティブを挿入する必要があるようです。

于 2016-02-17T19:09:58.687 に答える