gpt4 book ai didi

python - 编译 swig 输出时找不到 arrayobject.h

转载 作者:行者123 更新时间:2023-11-28 04:59:47 27 4
gpt4 key购买 nike

我发现很多类似的问题,人们对这个文件有疑问。我知道头文件在哪里,我用 -I 解决 g++,因为人们通常会回答前面的问题。我做了所有这些,但他们没有工作。 1 , 2

sum_array_wrap.cpp:3124:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
g++: error: sum_array_wrap.o: No such file or directory

build.sh

swig -python -c++ -o sum_array_wrap.cpp sum_array.i
g++ -c sum_array.cpp -o sum_array.o -fpic -std=c++0x
g++ -I/usr/include/python2.7 -I /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ -c sum_array_wrap.cpp -o sum_array.o -fpic -std=c++0x
g++ sum_array_wrap.o sum_array.o -o _sum_array.so -shared -Wl,-soname,_sum_array

你有解决办法吗? codes.zip

/* File sum_array.cpp */

/* Define function implementation */
double sum_array(double* input_array, int length) {

/* Initialize sum */
double sum = 0.;

/* Compute sum of array elements */
for (int i=0; i < length; i++)
sum += input_array[i];

return sum;
}

//*******************************************************//

/* File sum_array.h */

/* Define function prototype to take in a NumPy array */
double sum_array(double* input_array, int length);

//*******************************************************//
/* File sum_array.i */
%module sum_array

%{
#define SWIG_FILE_WITH_INIT
#include "sum_array.h"
%}

/* Include the NumPy typemaps library */
%include "numpy.i"

%init %{
import_array();
%}

/* Typemap for the sum_list(double* input_list, int length) C/C++ routine */
%apply (double* IN_ARRAY1, int DIM1) {(double* input_array, int length)};
/*the first tuple is a pair of the typemap (array type and dimension)
while the second is the function signature to match using that typemap.*/

%include "sum_array.h"

最佳答案

您通过了 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy,但 SWIG 希望您在“include”处停止,因为它是寻找 numpy/arrayobject.h

关于python - 编译 swig 输出时找不到 arrayobject.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362651/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com