How to use SWIG with "using"
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
开发者_如何学Go
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).
MSDN has this to say:
Note the difference between the using directive and the using declaration : the using declaration allows an individual name to be used without qualification, the using directive allows all the names in a namespace to be used without qualification.
(I'm guessing that) SWIG supports the "using directive" but not the "using declaration".
That is to say, you can use:
using namespace somenamespace::mynamespace;
But you can't use:
using somenamespace::mynamespace::MySymbol;
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 does support "using declarations". Your syntax error needs further diagnosis. I suggest looking at the preprocessed output using
$ swig -E -c++ -ocaml -I/opt/coherence-cpp/include coh.i
I decided in the end not to use SWIG for this.
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/
精彩评论