開發平台(Platform): (Ex: Win10, Linux, ...)
Win10 and Ubuntu 16
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC, VC++ and g++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
None
問題(Question):
目的:
想在python中呼叫C/C++C函式對Numpy array 做運算
現況:
目前參考下面連結實作也成功了
https://goo.gl/EcUqc7
程式放在:
https://github.com/ChiFang/question/tree/master/python_call_c
p.s 為了在windows也能跑我有加了 DLL_EXPORT
問題:
無論在linux還是windows上 只要把.c改成.cpp或使用g++編譯
python 呼叫產生的動態連結都會出現
AttributeError: ./ctest.so: undefined symbol: cfun >> on linux
AttributeError: function 'cfun' not found >> on windows
請問各位大大 我是否還少做了甚麼設定? 懇請指點
餵入的資料(Input):
從python 傳入numpy陣列給C/C++函式做處理
預期的正確結果(Expected Output):
所有陣列數值變2倍
錯誤結果(Wrong Output):
使用動態連結時找不到函式
程式碼(Code):(請善用置底文網頁, 記得排版)
ctest.c:
#include <stdio.h>
#ifdef _MSC_VER
#define DLL_EXPORT __declspec( dllexport )
#else
#define DLL_EXPORT
#endif
DLL_EXPORT void cfun(const void * indatav, int rowcount, int colcount, void *
outdatav)
{
//void cfun(const double * indata, int rowcount, int colcount, double *
outdata) {
const double * indata = (double *)indatav;
double * outdata = (double *)outdatav;
int i;
puts("Here we go!");
for (i = 0; i < rowcount * colcount; ++i) {
outdata[i] = indata[i] * 2;
}
puts("Done!");
}
補充說明(Supplement):