2016-11-06 150 views
3

我使用SWIG來翹曲一個非常簡單的C++類。 boost ptime用於該C++類。SWIG錯誤升壓:: posix_time :: 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... 
    } 
}; 

回答

0

的朋友邁克和我解決。

正確的接口文件是如以下的(不提升壓報頭):

/* File: example.i */ 
%module example 

%{ 
#define SWIG_FILE_WITH_INIT 
#include "example.h" 
%} 

%include "example.h" 

的大口執行命令(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 

的大口執行命令(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 

只更改最後一行。