开发平台(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):