需要哪个 $path 以便 g++/pybind11 可以找到 Python.h?
Which $path is needed so g++/pybind11 could locate Python.h?
我开始使用 pybind11
(在 Ubuntu 16.04 和 Python 2.7 上)。
为了试水,我围绕我的 c++ 库创建了一个无所事事的包装器。唉,编译找不到Python.h
:
$ g++ -std=c++0x -fPIC -pedantic -g -Wno-missing-field-initializers -Wno-switch -Wno-multichar -ftree-vectorize -ftree-vectorize -mssse3 backend.h uvc-v4l2.cpp wrap.cpp -o wrap.so
backend.h:4:9: warning: #pragma once in main file
#pragma once
^
In file included from /usr/local/include/pybind11/pytypes.h:12:0,
from /usr/local/include/pybind11/cast.h:13,
from /usr/local/include/pybind11/attr.h:13,
from /usr/local/include/pybind11/pybind11.h:36,
from wrap.cpp:1:
/usr/local/include/pybind11/common.h:72:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
不过,我似乎有文件:
$ find /usr -name Python.h
/usr/include/python2.7/Python.h
/usr/include/python3.5m/Python.h
我应该更正哪个(路径?)以便 g++
能够找到 Python.h
?
备注:
$ apt list | grep -iE -- '^python.-dev|^python-dev'
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
python-dev/xenial,now 2.7.11-1 amd64 [installed]
python3-dev/xenial,now 3.5.1-3 amd64 [installed]
$ dpkg -S Python.h
libpython2.7-dev:amd64: /usr/include/python2.7/Python.h
libpython3.5-dev:amd64: /usr/include/python3.5m/Python.h
$ dpkg -L python2.7-dev
/.
/usr
/usr/bin
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/doc
/usr/share/doc/python2.7
/usr/share/doc/python2.7/x86_64-linux-gnu
/usr/share/doc/python2.7/x86_64-linux-gnu/test_results.gz
/usr/share/doc/python2.7/x86_64-linux-gnu/pybench.log.gz
/usr/share/doc/python2.7/gdbinit.gz
/usr/share/doc/python2.7/HISTORY.gz
/usr/share/doc/python2.7/README.valgrind.gz
/usr/share/doc/python2.7/README.maintainers
/usr/bin/python2.7-config
/usr/share/man/man1/python2.7-config.1.gz
/usr/share/doc/python2.7-dev
-I/usr/include/python2.7
-I
标志将目录添加到要搜索头文件的目录列表中。如果您想要 python3.5 等价物,则将 2.7 替换为 3.5m
获得此标志的更可靠方法是使用pkg-config
。例如:
$ pkg-config --cflags python
-I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7
$ pkg-config --cflags python3
-I/usr/include/python3.6m -I/usr/include/x86_64-linux-gnu/python3.6m
我开始使用 pybind11
(在 Ubuntu 16.04 和 Python 2.7 上)。
为了试水,我围绕我的 c++ 库创建了一个无所事事的包装器。唉,编译找不到Python.h
:
$ g++ -std=c++0x -fPIC -pedantic -g -Wno-missing-field-initializers -Wno-switch -Wno-multichar -ftree-vectorize -ftree-vectorize -mssse3 backend.h uvc-v4l2.cpp wrap.cpp -o wrap.so
backend.h:4:9: warning: #pragma once in main file
#pragma once
^
In file included from /usr/local/include/pybind11/pytypes.h:12:0,
from /usr/local/include/pybind11/cast.h:13,
from /usr/local/include/pybind11/attr.h:13,
from /usr/local/include/pybind11/pybind11.h:36,
from wrap.cpp:1:
/usr/local/include/pybind11/common.h:72:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
不过,我似乎有文件:
$ find /usr -name Python.h
/usr/include/python2.7/Python.h
/usr/include/python3.5m/Python.h
我应该更正哪个(路径?)以便 g++
能够找到 Python.h
?
备注:
$ apt list | grep -iE -- '^python.-dev|^python-dev'
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
python-dev/xenial,now 2.7.11-1 amd64 [installed]
python3-dev/xenial,now 3.5.1-3 amd64 [installed]
$ dpkg -S Python.h
libpython2.7-dev:amd64: /usr/include/python2.7/Python.h
libpython3.5-dev:amd64: /usr/include/python3.5m/Python.h
$ dpkg -L python2.7-dev
/.
/usr
/usr/bin
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/doc
/usr/share/doc/python2.7
/usr/share/doc/python2.7/x86_64-linux-gnu
/usr/share/doc/python2.7/x86_64-linux-gnu/test_results.gz
/usr/share/doc/python2.7/x86_64-linux-gnu/pybench.log.gz
/usr/share/doc/python2.7/gdbinit.gz
/usr/share/doc/python2.7/HISTORY.gz
/usr/share/doc/python2.7/README.valgrind.gz
/usr/share/doc/python2.7/README.maintainers
/usr/bin/python2.7-config
/usr/share/man/man1/python2.7-config.1.gz
/usr/share/doc/python2.7-dev
-I/usr/include/python2.7
-I
标志将目录添加到要搜索头文件的目录列表中。如果您想要 python3.5 等价物,则将 2.7 替换为 3.5m
获得此标志的更可靠方法是使用pkg-config
。例如:
$ pkg-config --cflags python
-I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7
$ pkg-config --cflags python3
-I/usr/include/python3.6m -I/usr/include/x86_64-linux-gnu/python3.6m