如何使用configure的“prefix”选项将构建输出到指定目录?

3
我正在尝试在Clear Linux上构建glibc 2.27,可以在此处获取:https://www.gnu.org/software/libc/sources.html 根据帮助文档,我应该使用prefix命令将其构建到源文件夹外的目录中。据我所知,我正在按照安装指南所描述的进行操作。

Configuring and compiling the GNU C Library

The GNU C Library cannot be compiled in the source directory. You must build it in a separate build directory. For example, if you have unpacked the GNU C Library sources in '/src/gnu/glibc-VERSION', create a directory '/src/gnu/glibc-build' to put the object files in. This allows removing the whole build directory in case an error occurs, which is the safest way to get a fresh start and should always be done.

From your object directory, run the shell script 'configure' located at the top level of the source tree. In the scenario above, you'd type

 $ ../glibc-VERSION/configure ARGS...

Please note that even though you're building in a separate build directory, the compilation may need to create or modify files and directories in the source directory.

'configure' takes many options, but the only one that is usually mandatory is '--prefix'. This option tells 'configure' where you want the GNU C Library installed. This defaults to '/usr/local', but the normal setting to install as the standard system library is '--prefix=/usr' for GNU/Linux systems and '--prefix=' (an empty prefix) for GNU/Hurd systems.

所以,我认为我做得很正确,但它仍然给我一个关于在不同目录中构建的错误:

james@clr ~/Downloads/glibc $  ./configure --prefix=/home/james/Downloads/glibc-build/
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for readelf... readelf
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ can link programs... yes
configure: error: you must configure in a separate build directory

你为什么需要/想要从源代码构建它? - uzsolt
2个回答

14
你需要创建一个构建目录,并从中运行configure脚本。你的情况:
mkdir /home/james/Downloads/glibc-build/
cd /home/james/Downloads/glibc-build/
~/Downloads/glibc/configure

--prefix选项将更改安装目录(make install)。


谢谢,这解决了我的configure问题...但是我应该从哪里运行make install呢?我在/home/james/Downloads/glibc-build/和~/Downloads/glibc/都尝试过了,但没有成功。 - Stonecraft
我认为应该从构建目录运行 (cd ~/Downloads/glibc-build && make && make install)。您的错误信息是什么? - uzsolt
1
请注意,执行“make install”(或更可能的是“sudo make install”)很有可能使您的系统无法启动。 - Employed Russian
为什么这个错误信息这么不对呢?它应该是这样的 configure: error: 你必须从目标构建目录运行 configure - ThePhi
你是如何尝试构建的? - uzsolt

2

交叉编译 glibc 的过程与其他库和项目类似,但是,在 glibc 的特定情况下,我们提取项目的文件夹和生成配置文件的文件夹是不同的。因此,需要创建一个文件夹来保存我们生成的配置文件。

因此,在您下载并提取 glibc 到一个文件夹后,您必须退出该文件夹并创建另一个文件夹,然后从这个新文件夹运行 configure 脚本。

例如:

# Making a folder to hold source code

cd $HOME/Downloads
mkdir glibc-build
cd glibc-build

# Downloading glibc
wget https://ftp.gnu.org/gnu/libc/glibc-2.27.tar.gz

# Extracting glibc
tar -xvf glibc-2.27.tar.gz

# Creating folder to hold generate config files
mkdir configs_glibc && cd configs_glibc 

# Run configure script
../glibc-2.27/configure --prefix=$HOME/Downloads/glibc-build/configs_glibc

对于编译和安装,您需要继续进入configs_glibc并运行:

# Compiling
make 
# Installing
make install

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