使用numpy扩展的C程序的Makefile

6
请问确定numpy包含正确路径的最简单/最优雅的方法是什么?然后通过make命令使用它?目前我正在使用
gcc ... -I/usr/include/python2.7/ -I/usr/lib/python2.7/site-packages/numpy/core/include/numpy/
我希望根据构建所在的系统自动选择这两个包含文件。
看起来我可以像这样获取第二个包含文件:
python -c "import numpy; print numpy.__path__[0] + 'core/include/numpy/'"

但是我对第一个不确定,即使我确定了,我仍然不确定如何在makefile中最好地使用它(以一种简单/优雅的方式)。

2个回答

3

numpy.get_include() 是获取包含文件路径的最简单和最好的方法。如果您的 C 扩展模块使用了 numpy,那么在 Extension 中,您需要使用 include_dirs=[numpy.get_include()]。为什么 numpy.get_include() 没有任何文档我不知道。

然后你可以像 user1056255 建议的那样做,但稍微改进一下...

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

0

所以经过一些谷歌搜索和实验,这就是我想出来的:

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

不确定它有多可靠,但目前似乎在所有机器上都能正常工作。

我不得不使用 $(shell ...) 从 shell 输出中设置 make 变量,因为 mux 提出的方法对我不起作用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接