我正在用python编写一个程序。现在我想使用 ctypes 来使用我在 c++ 中拥有的类的一些功能。所以基本上,我在 python 中有一个数据数组。我在 c++ 中有另一个程序,它应该使用该数组并将其转换为图像类。这是我在 C++ 中的程序。我已经在linux中制作了makefile并且可以编译。
文件名是“pclink.cpp”
#include <stdio.h>
#include "MImage.h"
#include<stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
int conv(double* data, int x,int y, int z, int len) {
MImage M;
//M.MLoadFromArray(data,x,y,z,len);
return 0;
}
#ifdef __cplusplus
}
#endif
我还制作了 .so 和 .o 文件,一切看起来都很好。但是当我在 python 中输入
import numpy as np
import ctypes
import os
pclink = np.ctypeslib.load_library('pclink','.')
这是我收到的信息
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
pclink=np.ctypeslib.load_library('pclink','.')
File "/usr/lib/python2.7/dist-packages/numpy/ctypeslib.py", line 131, in load_library
raise exc
OSError: /home/lucy94/pclink.so: undefined symbol: _ZN6MImage14MLoadFromArrayEPdiiii
以前我试图将 c++ 和 python 与一个没有任何类的简单程序链接,它工作正常。似乎问题是当我尝试从另一个类定义对象时。所以有人知道如何解决这个问题吗?谢谢