boost::posix_time::ptime 转换的 SWIG 错误

SWIG error for boost::posix_time::ptime conversion

我正在使用 SWIG 扭曲一个非常简单的 C++ class。 在该 C++ class.

中使用了 boost ptime

当我尝试执行命令时

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...
    }   
};

我和迈克朋友解决了。

正确的接口文件如下(未提及boost头文件):

/* 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执行命令为(Ubuntu14.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

只更改最后一行。