我尝试用cython包装一个C ++类,它编译好了,但是当我导入扩展时,我发现
ImportError: ./svd.so: undefined symbol: _ZTI5model
这是C ++头文件:
首先,“model.h”,model是svd的基类。
// model.h
#ifndef MODEL_H_
#define MODEL_H_
#include "common.h"
#include "Data.h"
class model {
protected:
Data data;
public:
model(Data& data);
virtual float predict(uint uid, uint mid);
// evaluate using testset and return final RMSE
virtual float evaluate();
// put predictions to file
void output(string filename);
virtual void onestep();
virtual ~model();
};
#endif /* MODEL_H_ */
然后是svd.h,svd继承自模型。
// svd.h
#ifndef SVD_H_
#define SVD_H_
#include "../common.h"
#include "../model.h"
#include "../Data.h"
#define K_NUM 50
namespace SVD{
class svd : model {
public:
svd(Data &data);
void init(uint max_step, float alpha1, \
float alpha2, float beta1, float beta2);
float predict(UidType uid, ItemType mid);
float evaluate();
void onestep();
~svd();
}; // end class svd
void initModel(uint max_step, float alpha1, float alpha2, float beta1, float beta2);
};// end namespace svd
#endif /* SVD_H_ */
最后,pyx文件
# distutils: language = c++
# distutils: sources = ../model.cpp ../models/svd.cpp ../common.cpp ../Data.cpp ../model.cpp
cdef extern from "../models/svd.h" namespace "SVD":
cdef cppclass svd:
pass
和我的setup.py文件
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize(
["svd.pyx"], # our Cython source
language="c++", # generate C++ code
))
我认为符号“模型”可能是svd的基类,