CPython 可以用 Clang 编译吗?
Can CPython be compiled with Clang?
我正在尝试使用 Clang 构建 CPython,具有非常具体的要求:
- Python 2.7.14
- CentOS 6.9(但适应 Ubuntu 16.04),x64
- LLVM 5.0.0
我尝试将环境变量 CC
设置为我的 clang 可执行文件位置(即 /opt/llvm/5/bin/clang
,但 ./configure
命令失败并显示以下内容:
configure: error: C compiler cannot create executables
我应该设置什么标志才能使这个构建工作?
tried setting env variable CC to my clang executable location
在Linux上,在Bash中定义一个别名如下:
alias cc="clang"
在我的系统上,我将其设置为 alias cc="clang-11"
此外,请务必在系统上安装所有 clang 和 llvm 软件包。
正如 OP post 上的评论者指出的那样,您可以使用 clang 编译 cpython。以下是可重现的指令,采用 Dockerfile 的形式。
FROM ubuntu:16.04
WORKDIR /opt/cpython-2.7.14
RUN apt-get update -qq \
&& apt-get install --yes build-essential curl \
# Install clang
&& curl -fsSL https://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz \
| tar xJ -C /usr/local --strip-components 1 \
&& curl -fsSL https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz \
| tar xz --strip-components 1 \
&& CC=/usr/local/bin/clang ./configure --prefix /usr/local/cpython-2.7.14 \
&& make \
&& make install
ENTRYPOINT ["/usr/local/cpython-2.7.14/bin/python"]
docker build --tag cpython:2.7 .
docker run --rm cpython:2.7 --version
# Python 2.7.14
很难说 OP 的原始问题是什么,因为它似乎是 clang 安装的问题。查看配置日志将提供更多信息。
免责声明:Python 2 的生命周期已结束,ubuntu 16.04 的生命周期将于 2021 年 4 月结束。
我正在尝试使用 Clang 构建 CPython,具有非常具体的要求:
- Python 2.7.14
- CentOS 6.9(但适应 Ubuntu 16.04),x64
- LLVM 5.0.0
我尝试将环境变量 CC
设置为我的 clang 可执行文件位置(即 /opt/llvm/5/bin/clang
,但 ./configure
命令失败并显示以下内容:
configure: error: C compiler cannot create executables
我应该设置什么标志才能使这个构建工作?
tried setting env variable CC to my clang executable location
在Linux上,在Bash中定义一个别名如下:
alias cc="clang"
在我的系统上,我将其设置为 alias cc="clang-11"
此外,请务必在系统上安装所有 clang 和 llvm 软件包。
正如 OP post 上的评论者指出的那样,您可以使用 clang 编译 cpython。以下是可重现的指令,采用 Dockerfile 的形式。
FROM ubuntu:16.04
WORKDIR /opt/cpython-2.7.14
RUN apt-get update -qq \
&& apt-get install --yes build-essential curl \
# Install clang
&& curl -fsSL https://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz \
| tar xJ -C /usr/local --strip-components 1 \
&& curl -fsSL https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz \
| tar xz --strip-components 1 \
&& CC=/usr/local/bin/clang ./configure --prefix /usr/local/cpython-2.7.14 \
&& make \
&& make install
ENTRYPOINT ["/usr/local/cpython-2.7.14/bin/python"]
docker build --tag cpython:2.7 .
docker run --rm cpython:2.7 --version
# Python 2.7.14
很难说 OP 的原始问题是什么,因为它似乎是 clang 安装的问题。查看配置日志将提供更多信息。
免责声明:Python 2 的生命周期已结束,ubuntu 16.04 的生命周期将于 2021 年 4 月结束。