【发布时间】:2019-07-11 20:24:22
【问题描述】:
我正在尝试为 macOS 上的 Python3 扩展编译 C++ 代码,并且只有在 #include "$HOME/anaconda3/include/python3.6m/Python.h 时才能编译。有没有办法#include <Python/Python.h> 并让“包含”引用 anaconda Python.h 而不是系统 Python.h?
【问题讨论】:
我正在尝试为 macOS 上的 Python3 扩展编译 C++ 代码,并且只有在 #include "$HOME/anaconda3/include/python3.6m/Python.h 时才能编译。有没有办法#include <Python/Python.h> 并让“包含”引用 anaconda Python.h 而不是系统 Python.h?
【问题讨论】:
将您的 Python.h 放在名为 python3.6m 的目录中会有点尴尬,但这里有两种可能的解决方法:
将目录从 python3.6m 重命名为 Python,然后将参数 -I$HOME/anaconda3/include 添加到编译行,以告诉编译器解析从该文件夹开始的包含路径。
或者,您可以添加一个符号链接,以便可以通过两个不同的名称访问 python3.6m 目录,例如:
cd ~/anaconda3/include ; ln -s python3.6m Python
...然后将参数 -I$HOME/anaconda3/include 添加到您的编译器参数中(与步骤 1 相同)
【讨论】: