如何使用SWIG包装此内容?
usecase5.h
#ifndef __USECASE5_H__
#define __USECASE5_H__
#include <math.h>
namespace foo_namespace {
struct vec2
{
int x, y;
vec2() {}
explicit vec2( int a, int b )
{
x = a;
y = b;
}
vec2 & operator =( vec2 const & v ) { x = v.x; y = v.y; return *this; }
vec2 & operator/=( vec2 const & v ) { x /= v.x; y /= v.y; return *this; }
vec2 xx() const { return vec2(x,x); }
}
}
#endif
usecase6.h
#ifndef __USECASE6_H__
#define __USECASE6_H__
#include "usecase5.h"
namespace foo_namespace {
vec2 usecase6_f1(const vec2 & x);
}
#endif
usecase6.cpp
namespace foo_namespace {
vec2 usecase6_f1(const vec2 & x)
{
x = vec2();
}
}
example.i
// GENERATED BY gen_swig.py at 2016-10-04 21:46
%module example
%{
//#include "usecase1.h"
//#include "usecase2.h"
//#include "usecase3.h"
//#include "usecase4.h"
#include "usecase5.h"
#include "usecase6.h"
using namespace foo_namespace;
%}
//%include "usecase1.h"
//%include "usecase2.h"
//%include "usecase3.h"
//%include "usecase4.h"
%include "usecase5.h"
%include "usecase6.h"
用swig -python -c++ example.i
尝试了那个天真的example.i之后我会得到:
usecase5.h(19) : Warning 362: operator= ignored
usecase5.h(24) : Error: Syntax error in input(3).
那么,我怎么能包装这个小的虚拟c ++示例?
答案 0 :(得分:0)
似乎这不是与swig相关的任何问题,但更多关于c ++方面,修复它我只需要修复c ++问题:
usecase5.h
#ifndef __USECASE5_H__
#define __USECASE5_H__
#include <math.h>
namespace foo_namespace {
struct vec2
{
int x, y;
vec2() {}
explicit vec2( int a, int b )
{
x = a;
y = b;
}
vec2 & operator =( vec2 const & v ) { x = v.x; y = v.y; return *this; }
vec2 & operator/=( vec2 const & v ) { x /= v.x; y /= v.y; return *this; }
vec2 xx() const { return vec2(x,x); }
};
}
#endif
usecase6.cpp
#include "usecase5.h"
namespace foo_namespace {
vec2 usecase6_f1(const vec2 & x)
{
return x;
}
}
之后,包装器将成功构建并在python端正常工作。