Makefile for a C program that uses numpy extensions

Please, what is the easiest / most elegant way to determine the correct paths for numpy since they are present on the target system? And then use it with the make command? I'm currently using

gcc ... -I / usr / include / python2.7 / -I / usr / lib / python2.7 / site-packages / numpy / core / include / numpy /

and I would like these two options to be automatically selected based on the system on which the assembly is performed.

It looks like I can get the second option, for example:

python -c "import numpy; print numpy.__path__[0] + 'core/include/numpy/'" 

but I'm not sure about the first one, and even if I were, I would not be sure how best to use it from the makefile (in a simple / elegant way).

+6
source share
2 answers

numpy.get_include() is the easiest / best way to get inboxes. If your C extension uses numpy, then in Extension you should use include_dirs=[numpy.get_include()] . Why numpy.get_include() does not seem to have documentation that I don't know.

Then you can do as user1056255, but a little better ...

 CFLAGS = $(shell python-config --includes) $(shell python -c "import numpy; print '-I' + numpy.get_include()") 
+3
source

So, after some searches and experiments, this is what I came across:

 CFLAGS = $(shell python-config --includes) $(shell python -c "import numpy; print '-I' + numpy.__path__[0] + '/core/include/numpy/'") 

Not sure how reliable it is, but it seems to work on all machines.

I had to use $ (shell ...) to configure make variables from shell output, since the method suggested by mux did not work for me

0
source

Source: https://habr.com/ru/post/906943/


All Articles