我通过使用SWIG来扭曲一个非常简单的C ++类。 boost ptime用在那个C ++类中。
当我尝试执行命令
时swig -c++ -python example.i
有一个错误:
example.h:7: Warning 315: Nothing known about 'boost::posix_time::ptime'.
example.h:7: Warning 315: Nothing known about 'boost::posix_time::ptime'.
如何解决此问题?
example.i文件是:
//File: example.i
%module example
%{
#define SWIG_FILE_WITH_INIT
#include <boost/date_time/posix_time/ptime.hpp>
#include "example.h"
%}
// for std:string
%include "std_string.i"
// for vector
%include "std_vector.i"
%include stl.i
%include "example.h"
example.h文件是:
#pragma once
#include <string>
#include <boost/date_time/posix_time/ptime.hpp>
using std::string;
using boost::posix_time::ptime;
class Example{
public:
Example(string name, ptime timestamp){
// doSomething...
}
};
答案 0 :(得分:0)
朋友迈克和我解决了。
正确的接口文件如下(未提及升压头):
/* File: example.i */
%module example
%{
#define SWIG_FILE_WITH_INIT
#include "example.h"
%}
%include "example.h"
swig执行命令是(OSX):
swig -c++ -python example.i
g++ -O2 -fPIC -c example.h -std=c++11
g++ -O2 -fPIC -c example_wrap.cxx -I/Library/anaconda2/include/python2.7
g++ -bundle -flat_namespace -undefined suppress -o _example.so *.o
swig执行命令是(Ubuntu 14.04):
swig -c++ -python example.i
g++ -O2 -fPIC -c example.h -std=c++11
g++ -O2 -fPIC -c example_wrap.cxx -I/usr/include/python2.7
g++ -shared -o _example.so *.o
仅更改最后一行。