2

我正在尝试在 C++ 库上使用 SWIG 2.0.4,我的 .i 文件中有以下内容:

%module coh
%{
#include "coherence/lang.ns"
#include "coherence/net/CacheFactory.hpp"
#include "coherence/net/NamedCache.hpp"
%}

%include "coherence/lang.ns"
%include "coherence/net/CacheFactory.hpp"
%include "coherence/net/NamedCache.hpp"

我痛饮它:

$ swig -c++ -ocaml -I/opt/coherence-cpp/include coh.i

但得到错误信息:

/opt/coherence-cpp/include/coherence/net/CacheFactory.hpp:31: Error: Syntax error in input(1)

该文件的第 31 行是:

using coherence::run::xml::XmlElement;

using不支持关键字吗?是否有解决方法,或者我应该只编写自己的 C++ 包装器,然后 SWIG 来代替?谢谢!

更新:我决定编写自己的包装器(将来,从一开始就采用不同的方法)。

4

5 回答 5

2

MSDN有这样的说法:

注意 using 指令和 using 声明之间的区别: using 声明允许使用单个名称而无需限定,而 using 指令允许使用名称空间中的所有名称而无需限定。

(我猜)SWIG 支持“使用指令”,但不支持“使用声明”。

也就是说,你可以使用:

using namespace somenamespace::mynamespace;

但你不能使用:

using somenamespace::mynamespace::MySymbol;
于 2011-10-26T07:33:32.700 回答
1

using在 C++ 头文件中是一种不好的做法,因为它会传播到其他包含项,因此 SWIG 不支持它们的事实并不是什么大问题。

最好在您的标题中删除using,并继续 SWIG!

于 2011-08-24T11:50:12.790 回答
1

SWIG 确实支持“使用声明”。您的语法错误需要进一步诊断。我建议使用

$ swig -E -c++ -ocaml -I/opt/coherence-cpp/include coh.i
于 2012-06-30T09:03:25.287 回答
0

我最终决定不为此使用 SWIG

于 2011-08-24T11:24:56.897 回答
0

SWIG 3.0.11 added support for C++11 type aliasing with using keyword.

https://sourceforge.net/p/swig/news/2016/12/swig-3011-released/

于 2017-06-21T01:15:41.577 回答