如何通过“using”来使用 SWIG
我正在尝试在 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 来代替?谢谢!
更新:我决定编写我自己的包装器(将来,从一开始就采取不同的方法)。
I am attempting to use SWIG 2.0.4 on a C++ library, I have the following in my .i
file:
%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"
I swig it with:
$ swig -c++ -ocaml -I/opt/coherence-cpp/include coh.i
But get the error message:
/opt/coherence-cpp/include/coherence/net/CacheFactory.hpp:31: Error: Syntax error in input(1)
Line 31 of that file is:
using coherence::run::xml::XmlElement;
Is the using
keyword not supported? Is there a workaround for this, or should I just write a C++ wrapper of my own, and SWIG that instead? Thanks!
UPDATE: I decided to write my own wrapper (and in future, to take a different approach from the start).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MSDN 有这样的说法:
(我猜)SWIG 支持“using 指令”,但不支持“using 声明”。
也就是说,你可以使用:
但不能使用:
MSDN has this to say:
(I'm guessing that) SWIG supports the "using directive" but not the "using declaration".
That is to say, you can use:
But you can't use:
在 C++ 标头中
using
是一种不好的做法,因为它会传播到其他包含内容,因此 SWIG 不支持它们这一事实并不是什么大问题。最好删除标头中的
using
,然后继续使用 SWIG!using
in C++ headers is a bad practice, as it gets propagated to other inclusions, so the fact that SWIG doesn't support them is not a big deal.Better remove
using
in your headers, and continue to SWIG!SWIG 确实支持“使用声明”。您的语法错误需要进一步诊断。我建议使用查看预处理的输出
SWIG does support "using declarations". Your syntax error needs further diagnosis. I suggest looking at the preprocessed output using
我最终决定 不使用 SWIG 来< /a>.
I decided in the end not to use SWIG for this.
SWIG 3.0.11 添加了对使用
using
关键字的 C++11 类型别名的支持。https://sourceforge.net/p/swig/news /2016/12/swig-3011-发布/
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/