我正在try 更新用于构建的Docker映像中的Boost版本.由于最新版本的Boost不能通过APT用于较旧的Ubuntu版本(在我的例子中是18.04LTS),我不得不从源代码构建Boost.我在CMake中遇到了一些奇怪的行为,仅当从源代码构建Boost时,而不是通过apt-get install libboost-all-dev
安装它.
在从源文件(Dockerfile中为BUILD_BOOST_FROM_SOURCE=1
)构建Boost时,CMake发现"错误的"Python版本:
#5 563.5 -- Found Boost: /usr/local/include (found version "1.65.1")
#5 564.1 -- Found Python: /usr/bin/python2.7 (found version "2.7.17") found components: Interpreter Development Development.Module Development.Embed
在安装Boost Via apt-get install libboost-all-dev
(Dockerfile中的BUILD_BOOST_FROM_SOURCE=0
)时,我得到了所需的配置:
#5 88.70 -- Found Boost: /usr/include (found version "1.65.1")
#5 89.16 -- Found Python: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter Development Development.Module Development.Embed
下面是我的Dockerfile的精简版本,它再现了这个问题,并在最后运行CMake来判断结果.我已经将Build Boost版本更改为通过APT安装的完全相同的版本,该问题对于较新的版本仍然存在.
FROM --platform=$BUILDPLATFORM ubuntu:bionic
ENV DEBIAN_FRONTEND noninteractive
ENV TZ America/New_York
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
ENV LANGUAGE en_US.UTF-8
ARG BOOST_VERSION=1.65.1 # adjusted to be equal to the one installed via apt-get
ENV BUILD_BOOST_FROM_SOURCE=1 # build from source or install via apt-get
RUN /bin/bash <<EOF
set -euxo pipefail
# Install package dependencies
apt-get update
apt-get install -y --no-install-recommends \
build-essential \
software-properties-common \
autoconf \
automake \
libtool \
pkg-config \
ca-certificates \
libssl-dev \
wget \
git \
curl \
gnupg \
language-pack-en \
locales \
locales-all \
vim \
gdb \
valgrind
# install python
apt-get install -y --no-install-recommends \
python \
python-dev \
python3 \
python3-pip \
apt-get clean
# perform the rest in the /tmp dir
cd /tmp
if [ "$BUILD_BOOST_FROM_SOURCE" -eq 1 ]; then \
# build and install the specific boost version from source given by the BOOST_VERSION ARG
wget https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_$(echo ${BOOST_VERSION} | tr . _).tar.bz2 && \
tar --bzip2 -xf boost_$(echo ${BOOST_VERSION} | tr . _).tar.bz2 && \
cd boost_$(echo ${BOOST_VERSION} | tr . _) && \
./bootstrap.sh --prefix=/usr/local && \
./b2 install; \
else \
# Install boost simply via apt-get
apt-get install -y --no-install-recommends \
libboost-all-dev; \
fi
# Use kitware's CMake repository for an up-to-date version and install cmake
curl -sSf https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add -
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
apt-get install -y --no-install-recommends cmake
# check the boost and python versions found by cmake
echo -e 'cmake_minimum_required(VERSION 3.12)
project(JustCheckingSomeVersions)
find_package(Boost)
find_package(Python COMPONENTS Interpreter Development)
' > CMakeLists.txt
cmake .
EOF
我try 以各种方式更改安装顺序,并将--with-python=/usr/bin/python3
传递给bootstrap.sh.所有这些措施都没有帮助,我也没有 idea ,也不太了解这里所涉及的错综复杂的情况,无法取得进展.如何确保CMake在此Docker镜像中从源代码构建Boost时仍能找到Python3.x?
编辑:
多亏了Qyriads comment,我能够进一步追踪到CMake没有找到3.6版本的Python.h
头文件.库和可执行文件分别在/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.so
和/usr/bin/python3.6
找到.CMAKE_FIND_DEBUG_MODE
的输出显示如下:
#5 564.4 CMake Debug Log at /usr/share/cmake-3.25/Modules/FindPython/Support.cmake:2963 (find_path):
#5 564.4 find_path called with the following settings:
#5 564.4
#5 564.4 VAR: _Python_INCLUDE_DIR
#5 564.4 NAMES: "Python.h"
#5 564.4 Documentation: Path to a file.
#5 564.4 Framework
#5 564.4 Only Search Frameworks: 0
#5 564.4 Search Frameworks Last: 0
#5 564.4 Search Frameworks First: 0
#5 564.4 AppBundle
#5 564.4 Only Search AppBundle: 0
#5 564.4 Search AppBundle Last: 0
#5 564.4 Search AppBundle First: 0
#5 564.4 CMAKE_FIND_USE_CMAKE_PATH: 1
#5 564.4 CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
#5 564.4 CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 0
#5 564.4 CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 0
#5 564.4 CMAKE_FIND_USE_INSTALL_PREFIX: 1
#5 564.4
#5 564.4 find_path considered the following locations:
#5 564.4
#5 564.4 /usr/include/python3.6m/Python.h
#5 564.4 /usr/include/Python.h
#5 564.4 /usr/Python.h
#5 564.4
#5 564.4 The item was not found.
#5 564.4
#5 564.4 Call Stack (most recent call first):
#5 564.4 /usr/share/cmake-3.25/Modules/FindPython.cmake:540 (include)
#5 564.4 CMakeLists.txt:5 (find_package)
#5 564.4
#5 564.4 CMake Debug Log at /usr/share/cmake-3.25/Modules/FindPython/Support.cmake:2975 (find_path):
#5 564.4 find_path called with the following settings:
#5 564.4
#5 564.4 VAR: _Python_INCLUDE_DIR
#5 564.4 NAMES: "Python.h"
#5 564.4 Documentation: Path to a file.
#5 564.4 Framework
#5 564.4 Only Search Frameworks: 0
#5 564.4 Search Frameworks Last: 0
#5 564.4 Search Frameworks First: 0
#5 564.4 AppBundle
#5 564.4 Only Search AppBundle: 0
#5 564.4 Search AppBundle Last: 0
#5 564.4 Search AppBundle First: 0
#5 564.4 CMAKE_FIND_USE_CMAKE_PATH: 1
#5 564.4 CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
#5 564.4 CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
#5 564.4 CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
#5 564.4 CMAKE_FIND_USE_INSTALL_PREFIX: 1
#5 564.4
#5 564.4 find_path considered the following locations:
#5 564.4
#5 564.4 /usr/local/sbin/Python.h
#5 564.4 /usr/local/bin/Python.h
#5 564.4 /usr/sbin/Python.h
#5 564.4 /usr/bin/Python.h
#5 564.4 /sbin/Python.h
#5 564.4 /bin/Python.h
#5 564.4 /usr/local/include/x86_64-linux-gnu/Python.h
#5 564.4 /usr/local/include/Python.h
#5 564.4 /usr/local/Python.h
#5 564.4 /usr/include/x86_64-linux-gnu/Python.h
#5 564.4 /usr/include/Python.h
#5 564.4 /usr/Python.h
#5 564.4 /include/x86_64-linux-gnu/Python.h
#5 564.4 /include/Python.h
#5 564.4 /usr/X11R6/include/x86_64-linux-gnu/Python.h
#5 564.4 /usr/X11R6/include/Python.h
#5 564.4 /usr/X11R6/Python.h
#5 564.4 /usr/pkg/include/x86_64-linux-gnu/Python.h
#5 564.4 /usr/pkg/include/Python.h
#5 564.4 /usr/pkg/Python.h
#5 564.4 /opt/include/x86_64-linux-gnu/Python.h
#5 564.4 /opt/include/Python.h
#5 564.4 /opt/Python.h
#5 564.4 /usr/include/X11/Python.h
#5 564.4
#5 564.4 The item was not found.
通过apt-get安装Boost时,此标头低于/usr/include/python3.6m/Python.h
.