est.java 2 错误 找不到符号_找不到Cython/Python符号PyString\u Typ
我試圖調(diào)用Cython的C++代碼,并遵循official guide。在
但是,當(dāng)在python中導(dǎo)入已編譯的模塊時,我得到以下錯誤。在---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in ()
----> 1 import rect
ImportError: /home/userName/estCppLibrary/rect.so: undefined symbol: PyString_Type
我必須補(bǔ)充,我沒有管理員權(quán)限,必須在~/.local/lib本地安裝Cython。在擁有sudo權(quán)限和默認(rèn)路徑的私人筆記本上,我的代碼可以正常工作。在
這是我的密碼。在
^{pr2}$
-#Rectangle.h
namespace shapes {
class Rectangle {
public:
int x0, y0, x1, y1;
Rectangle();
Rectangle(int x0, int y0, int x1, int y1);
~Rectangle();
int getArea();
void getSize(int* width, int* height);
void move(int dx, int dy);
};
}
-#Rectangle.cpp
namespace shapes {
Rectangle::Rectangle() { }
Rectangle::Rectangle(int X0, int Y0, int X1, int Y1) {
x0 = X0;
y0 = Y0;
x1 = X1;
y1 = Y1;
}
Rectangle::~Rectangle() { }
int Rectangle::getArea() {
return (x1 - x0) * (y1 - y0);
}
void Rectangle::getSize(int *width, int *height) {
(*width) = x1 - x0;
(*height) = y1 - y0;
}
void Rectangle::move(int dx, int dy) {
x0 += dx;
y0 += dy;
x1 += dx;
y1 += dy;
}
}
-#rect.pyx
# distutils: language = c++
# distutils: sources = Rectangle.cpp
cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Rectangle:
Rectangle() except +
Rectangle(int, int, int, int) except +
int x0, y0, x1, y1
int getArea()
void getSize(int* width, int* height)
void move(int, int)
cdef class PyRectangle:
cdef Rectangle c_rect # hold a C++ instance which we're wrapping
def __cinit__(self, int x0, int y0, int x1, int y1):
self.c_rect = Rectangle(x0, y0, x1, y1)
def get_area(self):
return self.c_rect.getArea()
def get_size(self):
cdef int width, height
self.c_rect.getSize(&width, &height)
return width, height
def move(self, dx, dy):
self.c_rect.move(dx, dy)
總結(jié)
以上是生活随笔為你收集整理的est.java 2 错误 找不到符号_找不到Cython/Python符号PyString\u Typ的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux mysql关闭启动不了了,l
- 下一篇: 浦发腾讯动漫联名信用卡怎么提额