[問題] C/C++ 輸出動態連結給python呼叫
開發平台(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):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.230.27
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1516257790.A.3FF.html
推
01/18 15:04,
6年前
, 1F
01/18 15:04, 1F
→
01/18 15:16,
6年前
, 2F
01/18 15:16, 2F
推
01/18 16:06,
6年前
, 3F
01/18 16:06, 3F
→
01/18 16:31,
6年前
, 4F
01/18 16:31, 4F
→
01/18 16:32,
6年前
, 5F
01/18 16:32, 5F
→
01/18 16:35,
6年前
, 6F
01/18 16:35, 6F
推
01/18 17:23,
6年前
, 7F
01/18 17:23, 7F
推
01/20 16:55,
6年前
, 8F
01/20 16:55, 8F
推
01/20 23:12,
6年前
, 9F
01/20 23:12, 9F
→
01/20 23:13,
6年前
, 10F
01/20 23:13, 10F
→
01/22 08:36,
6年前
, 11F
01/22 08:36, 11F
→
01/22 08:36,
6年前
, 12F
01/22 08:36, 12F
推
01/22 09:40,
6年前
, 13F
01/22 09:40, 13F