简体   繁体   中英

arm64 to armhf cross compiler missing _POSIX_MATH_PATH

I'm building a cross compiler for a beagle bone black, so it needs gcc 8.3 and glib 2.28. Here is a script I found and changed with the newest versions of the other packages I found on the gnu mirror site:

#! /bin/bash -e

#-------------------------------------------------------------------------------------------
# This script will download packages for, configure, build and install a GCC cross-compiler.
# Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
# If you get an error and need to resume the script from some point in the middle,
# just delete/comment the preceding lines before running it again.
#
# See: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler
#-------------------------------------------------------------------------------------------

INSTALL_PATH=$HOME/.local/cross
TARGET="arm-none-linux-gnueabihf"
LINUX_ARCH=arm
PARALLEL_MAKE=-j4
BINUTILS_VERSION=binutils-2.39
GCC_VERSION=gcc-8.3.0
LINUX_KERNEL_VERSION=4.19.94-ti-r42
GLIBC_VERSION=glibc-2.28
MPFR_VERSION=mpfr-4.2.0
GMP_VERSION=gmp-6.2.1
MPC_VERSION=mpc-1.3.1
ISL_VERSION=isl-0.24
CLOOG_VERSION=cloog-0.18.1
export PATH=$INSTALL_PATH/bin:$PATH

# Download packages
[ -e "$LINUX_KERNEL_VERSION.zip" ] || curl -LO https://github.com/beagleboard/linux/archive/refs/tags/$LINUX_KERNEL_VERSION.zip
[ -e "$BINUTILS_VERSION.tar" ] || wget -nc https://ftp.gnu.org/gnu/binutils/$BINUTILS_VERSION.tar.gz
[ -e "$GCC_VERSION.tar" ] || wget -nc https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_VERSION.tar.gz
[ -e "$GLIBC_VERSION.tar" ] || wget -nc https://ftp.gnu.org/gnu/glibc/$GLIBC_VERSION.tar.xz
[ -e "$MPFR_VERSION.tar" ] || wget -nc https://ftp.gnu.org/gnu/mpfr/$MPFR_VERSION.tar.xz
[ -e "$GMP_VERSION.tar" ] || wget -nc https://ftp.gnu.org/gnu/gmp/$GMP_VERSION.tar.xz
[ -e "$MPC_VERSION.tar" ] || wget -nc https://ftp.gnu.org/gnu/mpc/$MPC_VERSION.tar.gz
[ -e "$ISL_VERSION.tar" ] || wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL_VERSION.tar.bz2
[ -e "$CLOOG_VERSION.tar" ] || wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$CLOOG_VERSION.tar.gz

[ -e "linux-$LINUX_KERNEL_VERSION" ] || unzip $LINUX_KERNEL_VERSION.zip
for f in *.tar.gz
do
  [ -e $f ] && gzip -d $f
done
for f in *.tar.bz2
do
  [ -e $f ] && bzip2 -d $f
done
for f in *.tar.xz
do
  [ -e $f ] && unxz $f
done

# Extract everything
for f in *.tar
do
  [ -e $(awk -F '.tar' '{print $1}' <<< $f) ] || tar xvf $f
done

# Make symbolic links
cd $GCC_VERSION
ln -sf `ls -1d ../mpfr-*/` mpfr
ln -sf `ls -1d ../gmp-*/` gmp
ln -sf `ls -1d ../mpc-*/` mpc
ln -sf `ls -1d ../isl-*/` isl
ln -sf `ls -1d ../cloog-*/` cloog
cd ..

# Step 1. Binutils
mkdir -p build-binutils
cd build-binutils
../$BINUTILS_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS --disable-werror
make $PARALLEL_MAKE
make install
cd ..

# Step 2. Linux Kernel Headers
cd linux-$LINUX_KERNEL_VERSION
make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$INSTALL_PATH/$TARGET headers_install
cd ..

# Step 3. C/C++ Compilers
mkdir -p build-gcc
cd build-gcc
../$GCC_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET --enable-languages=c,c++ --enable-shared --disable-multilib
make $PARALLEL_MAKE all-gcc LIMIT_H_TEST=true
make install-gcc
cd ..

# Step 4. Standard C Library Headers and Startup Files
mkdir -p build-glibc
cd build-glibc
../$GLIBC_VERSION/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include --disable-multilib libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers
make $PARALLEL_MAKE csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $INSTALL_PATH/$TARGET/lib
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $INSTALL_PATH/$TARGET/lib/libc.so
touch $INSTALL_PATH/$TARGET/include/gnu/stubs.h
cd ..

# Step 5. Compiler Support Library
cd build-gcc
make $PARALLEL_MAKE all-target-libgcc
make install-target-libgcc
cd ..

# Step 6. Standard C Library & the rest of Glibc
cd build-glibc
make $PARALLEL_MAKE
make install
cd ..

# Step 7. Standard C++ Library & the rest of GCC
cd build-gcc
make $PARALLEL_MAKE all
make install
cd ..

echo 'Success!'

This works and built me a cross compiler. However, when I use it, for some reason I get:

In file included from /home/mkurzynski/github/sc1-main-io/btf/googletest/googletest/src/gtest-all.cc:43:
/home/mkurzynski/github/sc1-main-io/btf/googletest/googletest/src/gtest-filepath.cc: In static member function ‘static testing::internal::FilePath testing::internal::FilePath::GetCurrentDir()’:
/home/mkurzynski/github/sc1-main-io/btf/googletest/googletest/src/gtest-filepath.cc:57:25: error: ‘_POSIX_PATH_MAX’ was not declared in this scope
 #define GTEST_PATH_MAX_ _POSIX_PATH_MAX
                         ^~~~~~~~~~~~~~~

I didn't expect this to happen since I'm compiling the googletest code and see #include <limits.h> and when cross compiling I also added LIMIT_H_TEST=true which I found from another script.

I've also seen people using sys root, but couldn't find a working example. For context, I'm compiling on ubuntu 22.10 aarch64 in qemu. Before this I was using Arm developer toolchain which didn't produce this error, but I couldn't find a version for aarch64 host and gcc 8.3.

What am I missing in the script?

As suggested in this answer gcc -c main.c -D_POSIX_C_SOURCE=1 , the constant is enabled by defining _POSIX_C_SOURCE .

This is similar to discussion about _POSIX_PATH_MAX variable is now located in posix1_lim.h here , suggests trying this command:

echo -e "#include <bits/posix1_lim.h>\n_POSIX_PATH_MAX" | /opt/<cross-pi-gcc-8.2.0>/bin/arm-linux-gnueabihf-gcc - -E -P -v

Looking thru the headers in the specific libc provided:

grep _POSIX_PATH_MAX -r  glibc-2.28
glibc-2.28/posix/bits/posix1_lim.h:#define  _POSIX_PATH_MAX     256

posix1_lim.h

/* Number of bytes in a pathname.  */
#define _POSIX_PATH_MAX         256

limits.h only includes posix limits when __USE_POSIX is defined.

#ifdef  __USE_POSIX
/* POSIX adds things to <limits.h>.  */
# include <bits/posix1_lim.h>
#endif

features.h enables __USE_POSIX when multiple conditions exist.

#if (defined _POSIX_SOURCE                                      \
     || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 1)       \
     || defined _XOPEN_SOURCE)
# define __USE_POSIX    1
#endif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM