3

I am trying to build glibc 2.27 on Clear Linux, obtained here: https://www.gnu.org/software/libc/sources.html

According to the help, I should build into a directory outside of the source folder using the prefix command. As far as I can tell, I am doing what is described in the installation help:

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.

so, I thought I was doing this correctly, but it still gave me an error about building in a different directory:

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
Stonecraft
  • 860
  • 1
  • 12
  • 30

2 Answers2

14

You have to create a build-directory and run configure script from it. Your case:

mkdir /home/james/Downloads/glibc-build/
cd /home/james/Downloads/glibc-build/
~/Downloads/glibc/configure

The --prefix option will change the install directory (make install).

uzsolt
  • 5,832
  • 2
  • 20
  • 32
  • Thanks, that got me past my problem with configure... but where do I run make install from? I ran in both /home/james/Downloads/glibc-build/ and ~/Downloads/glibc/ without success. – Stonecraft Jun 27 '18 at 18:57
  • I think should work from build directory (`cd ~/Downloads/glibc-build && make && make install`). What is your error message? – uzsolt Jun 28 '18 at 09:37
  • 1
    Note that doing `make install` (or, more likely `sudo make install`) is *very* likely to render your system unbootable. – Employed Russian Jun 30 '18 at 17:33
  • Why is this error message so wrong? It should be like `configure: error: you must run configure from the targeted build directory` – ThePhi Jun 06 '21 at 04:04
  • How did you try build? – uzsolt Jun 06 '21 at 08:14
0

The process to cross-compile glibc is similar to the other libraries and projects, BUT, In the specific case of glibc the folder where we extract the project and the folder where we generate our configuration files are diferent. So It's necessary to create a folder to hold our generated configuration files.

So, after you download and extract glibc in a folder, you have to exit this folder and create another, so run the configure script from this new folder.

Example:

# 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

For the compilation and installation, you continue inside the configs_glibc and run:

# Compiling
make 
# Installing
make install
Lincoln
  • 53
  • 6