0

I found many similar questions people had problem with this file. I know where the header file is and I address the g++ with -I, as people usually answered to previous questions. I did all of them, but they did not worked.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

Do you have a solution? 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"
0

1 Answer 1

1

You passed -I /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy, but SWIG is expecting you to stop at "include" since it's looking for numpy/arrayobject.h.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.