我尝试在C语言中为数组排序函数提供一个python包装器。C获取数组,将整数从最小到最大排序,然后返回数组。但是当我运行它时,我得到了一个错误:
在Traceback (most recent call last):
File "sortarray.py", line 25, in
newarray = sortArray(array)
File "sortarray.py", line 8, in sortArray
libsortarray.sortArray.argtypes = (ctypes.c_int, ctypes.POINTER(ctypes.c_int))
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7f84484280e0, sortArray): symbol not found
Python:
在
^{pr2}$
以及libsortarray函数
在int* sortArray(int, int*);
int* sortArray(int arraySize, int* array) {
int temp, i, j;
for (i=0; i
for (j=i+1; j
if (array[i] > array[j]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}