`arm-none-eabi-g++ -print-sysroot` is empty - ubuntu-20.04

If I unpacking the toolchain via gcc-arm-none-eabi-10.3-2021 and run
$ arm-none-eabi-g++ --help
...
-print-sysroot Display the target libraries directory.
...
$ arm-none-eabi-g++ -print-sysroot
$ /opt/gcc-arm-none-eabi-10.3-2021.07/bin/../arm-none-eabi
I get the sysroot path, but if I use the package manager
$ # ubuntu 20.04
$ sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi \
libnewlib-dev libstdc++-arm-none-eabi-newlib
$ arm-none-eabi-g++ --help
...
-print-sysroot Display the target libraries directory.
...
$ arm-none-eabi-g++ -print-sysroot
$ # I would expect /usr/lib/gcc/arm-none-eabi, but it's empty
the sysroot path is empty.
Is this always the case for apt install? Is there a way to avoid this?

Related

arm-none-eabi toolchain compile from source

For my current project we are having an issue which we can solve if we are able to recompile the arm toolchain (gcc, c++stdlib, nanolibc, etc) from source.
From the arm website I can download a snapshot of the source. I found a blog but it's outdated. The pdf he refers to no longer exists in this snapshot anyway.
Browsing through the extracted archive I can't seem to find any instructions how to compile.
Where can I find documentation how to compile arm-none-eabi from source?
The release notes available at the download site include build-from-source instructions.
I've made a quick transcription here, but future readers should be warned it may have become out-of-date.
How to build the toolchain from sources
You can build Arm GNU Toolchain from sources using Linaro ABE (Advanced Build Environment) and provided ABE manifest files.
Below example shows how to build gcc-arm-aarch64-none-elf toolchain from sources using Linaro ABE build system.
Instructions
ABE has a dependency on git-new-workdir and needs this tool to be installed in /usr/local/bin directory:
$ wget https://raw.githubusercontent.com/git/git/master/contrib/workdir/git-new-workdir
$ sudo mv git-new-workdir /usr/local/bin
$ sudo chmod +x /usr/local/bin/git-new-workdir
Clone ABE from the URL below and checkout the stablebranch (see Getting ABE):
$ git clone https://git.linaro.org/toolchain/abe.git
Create the build directory and change to it. Any name for the directory will work:
$ mkdir build && cd build
Configure ABE (from the build directory):
$ ../abe/configure
Download the toolchain manifest file, from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads, into the build folder, for the required toolchain, for example, gcc-arm-aarch64-none-elf-abe-manifest.txt:
$ wget https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/manifest/gcc-arm-aarch64-none-elf-abe-manifest.txt
Build toolchain (from the build directory):
$ ../abe/abe.sh --manifest gcc-arm-aarch64-none-elf-abe-manifest.txt --build all
The built toolchain will be installed and available for use in the builds/destdir/x86_64-unknown-linux-gnu/bin/ directory.
# Usage
# sudo ./build_arm
# Setup vars
export TARGET=arm-none-eabi
export PREFIX=/opt/gnuarm
export PATH=$PATH:$PREFIX/bin
export JN='-j 8'
export GCCVER=11.2.0
export BINUVER=2.37
rm -rf build-*
rm -rf gcc-*
rm -rf binutils-*
# Get archives
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUVER.tar.gz
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVER/gcc-$GCCVER.tar.gz
# Extract archives
tar xf binutils-$BINUVER.tar.gz
tar xf gcc-$GCCVER.tar.gz
# Build binutils
mkdir build-binutils
cd build-binutils
../binutils-$BINUVER/configure --target=$TARGET --prefix=$PREFIX
echo "MAKEINFO = :" >> Makefile
make $JN all
sudo make install
# Build GCC
mkdir ../build-gcc
cd ../build-gcc
../gcc-$GCCVER/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib --with-gnu-as --with-gnu-ld --enable-languages='c' --enable-frame-pointer=no
make $JN all-gcc
sudo make install-gcc
# Build libgcc.a
make $JN all-target-libgcc CFLAGS_FOR_TARGET="-g -O2"
sudo make install-target-libgcc

How to fix ./configure in MSYS2?

I'm trying to build libxc-4.3.4 in an MSYS2 shell on Windows 10. I've installed the latest version of MSYS2 (msys2-x86_64-20220319.exe) and followed the installation instructions. I've installed build tools using
pacman -S --needed base-devel mingw-w64-x86_64-toolchain autoconf
I've installed libxc dozens of time on Linux machines. The first step is
./configure --prefix /somewhere
But in MSYS2 I get
$ ./configure --prefix $PWD/../libxc
bash: ./configure: No such file or directory
How can I make this work?
MSYS2 prerequisites
First of all make sure MSYS2 has all programs that are needed.
In the MSYS2 shell first update the package manager information:
pacman -Syu --noconfirm
Then install the packages you need. I would recommend at least these:
pacman -S --noconfirm autoconf autoconf-archive automake make libtool pkg-config
Project sources
Next you should make sure the folder you are in actually has a configure script:
ls -l configure
A lot of projects these days are switching to more efficient build systems like CMake or Meson.
I usually use the following command in the projects source folder to check for several build systems:
ls -ld configure* m4 CMakeLists.txt cmake Makefile GNUmakefile setup.py scons SConscript SConstruct meson.build meson_options.txt *.pro *.proj *.sln BUILD.gn .gn 2> /dev/null
building libxc
For the libxc project I see there is a CMakeLists.txt file and also a configure.ac file.
So either you should look into using CMake or generate the configure file with:
touch README ChangeLog
autoreconf -f -i -I m4
I have just tried to build libxc in MSYS2 with CMake and Ninja and this worked:
# set the line below to the desired install location
INSTALLPREFIX=D:\Prog\changeme
# build static library
cmake -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DENABLE_PYTHON:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_static &&
ninja -Cbuild_static install/strip &&
echo SUCCESS
# build shared library
cmake -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DENABLE_PYTHON:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_shared &&
ninja -Cbuild_shared install/strip &&
echo SUCCESS

Installing gcc 4.1.0 on ubuntu

I have latest version of ubuntu, but the version of gcc is higher than what I want. How do I build gcc 4.1.0 or install gcc 4.1.0 on this.
I did not find steps to build gcc 4.1.0
Here are the steps to building gcc:
http://gcc.gnu.org/install/
Note that, while "It refers to the current development sources, instructions for specific released versions are included with the sources."
It is a typical* configure, make, make install process. The most important configure flag is probably --enable-languages. and --prefix of course. Also --program-suffix=-4.1 will cause the generated executable to be called gcc-4.1 instead of gcc. The prerequisites list may look scary but most of it is optional, especially if only building for C/C++.
[*] ok, not so typical: another caveat pointed out by JonathanWakely in the comments below is that you shouldn't build gcc in the source dir since that is not supported, so :
(after getting all the prerequisites)
[gcc-src-dir] $ cd ../my-build-dir
[my-build-dir] $ ../gcc-src-dir/configure $CONFIG_FLAGS
[my-build-dir] $ make
[my-build-dir] $ make install
And he pointed to a wiki page he wrote which will walk you through the whole process.
I had a few issues installing gcc 4.1.2 on ubuntu (12.04 in my case). This script sorted it for me:
#!/bin/tcsh
if ($#argv != 1) then
echo "Synopsis: $argv[0] <install_dir>"
exit(-1)
endif
setenv GCCINSTALL $argv[1]
setenv LIBRARY_PATH /usr/lib/x86_64-linux-gnu
setenv SRC ~/gccSrc
mkdir -p $SRC
cd $SRC
wget http://gcc.cybermirror.org/releases/gcc-4.1.2/gcc-4.1.2.tar.gz
tar xvf gcc-4.1.2.tar.gz
cd gcc-4.1.2
mkdir build
cd build
../configure --prefix=${GCCINSTALL} --disable-multilib
grep 4.1.2/missing Makefile
sed -i "s#${SRC}/gcc-4.1.2/missing##" Makefile
grep 4.1.2/missing Makefile
make bootstrap
make install

A clean Homebrew won't install anything

I was trying to install rabbitmq on OS X 10.6.8 with homebrew, and it failed.. so I tried wiping out my Homebrew installation and reinstalling. Howevever, now I get the same failure message for anything I try to install. I don't see any way to debug this either. Has anyone seen this before? I have XCode 3.2.6 installed as well. Here, I try to install git with
brew install git -v
Output
make -C templates DESTDIR='' install
: no custom templates yet
install -d -m 755 '/usr/local/Cellar/git/1.7.7.1/share/git-core/templates'
readlink: illegal option -- f
usage: readlink [-n] [file ...]
usage: dirname path
ls: /install_*: No such file or directory
(cd blt && tar cf - .) | \
(cd '/usr/local/Cellar/git/1.7.7.1/share/git-core/templates' && umask 022 && tar xof -)
/bin/sh: line 0: cd: /usr/local/Cellar/git/1.7.7.1/share/git-core/templates: No such file or directory
make[1]: *** [install] Error 1
make: *** [install] Error 2
==> Exit Status: 2
http://github.com/mxcl/homebrew/blob/master/Library/Formula/git.rb#L40
==> Environment
HOMEBREW_VERSION: 0.8
HEAD: 9a6bd3473936175163a642e28f6ce0b8a659cf6d
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_LIBRARY_PATH: /usr/local/Library/Homebrew
Hardware: 8-core 64-bit sandybridge
OS X: 10.6.8
Kernel Architecture: x86_64
Ruby: 1.8.7-249
/usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
Xcode: 3.2.6
GCC-4.0: build 5494
GCC-4.2: build 5666
LLVM: build 2335
MacPorts or Fink? false
X11 installed? true
==> Build Flags
CC: /usr/bin/gcc-4.2
CXX: /usr/bin/g++-4.2
LD: /usr/bin/gcc-4.2
CFLAGS: -O3 -march=core2 -w -pipe
CXXFLAGS: -O3 -march=core2 -w -pipe
MAKEFLAGS: -j8
Error: Failed executing: make prefix=/usr/local/Cellar/git/1.7.7.1 install
These existing issues may help you:
https://github.com/mxcl/homebrew/issues/6257
https://github.com/mxcl/homebrew/issues/6820
https://github.com/mxcl/homebrew/issues/6971
https://github.com/mxcl/homebrew/issues/7462
https://github.com/mxcl/homebrew/issues/8030
https://github.com/mxcl/homebrew/issues/8230
https://github.com/mxcl/homebrew/issues/8244
Otherwise, please report the bug:
https://github.com/mxcl/homebrew/wiki/checklist-before-filing-a-new-issue
:~ $
Assuming homebrew pulled down the files to /usr/local/Cellar/git/1.7.7.1 it looks like you might have an issue with the make command. A few things to try:
Check to see which 'make' is being used : which make by default should be at /usr/bin/make.
If #1 is pointing where you would expect you might try to build a simple hello world project with a make file just to check that it's working properly.

changing search-dirs for $ sudo gcc

On OS X I'm trying to install the zlib prerequisite for haskell's Cabal. I get this error:
$ sudo ./Setup build
Preprocessing library zlib-0.5.0.0…
ld: library not found for -lgmp
collect2: ld returned 1 exit status
linking dist/build/Codec/Compression/Zlib/Stream_hsc_make.o failed
command was: /usr/bin/gcc -lz -L/sw/lib/ghc-6.8.3/lib/bytestring-0.9.0.1.1 -L/sw/lib/ghc-6.8.3/lib/array-0.1.0.0 -L/sw/lib/ghc-6.8.3/lib/base-3.0.2.0 -L/sw/lib/ghc-6.8.3 -lm -lgmp -ldl dist/build/Codec/Compression/Zlib/Stream_hsc_make.o -o dist/build/Codec/Compression/Zlib/Stream_hsc_make
The library -lgmp is found in /sw/lib, so I can run that command ("/usr/bin/gcc ...") successfully if I manually add -L/sw/lib. The problem is that sudo doesn't know about /sw/lib. Behold:
$ gcc -print-search-dirs | grep sw
libraries: =/lib/i686-apple-darwin9/4.0.1/:/lib/:/usr/lib/i686-apple-darwin9/4.0.1/:/usr/lib/:./i686-apple-darwin9/4.0.1/:./:/sw/lib/i686-apple-darwin9/4.0.1/:/sw/lib/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../../i686-apple-darwin9/lib/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../../i686-apple-darwin9/lib/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../
$ sudo gcc -print-search-dirs | grep sw
$
How do I tell the sudo version of gcc to look in /sw/lib for libraries? Do I add an environment variable on root's .bash_profile? If so, which one?
UPDATE:
There’s probably a more proper way to do this, but here’s what worked. I created a bash script with this in it:
#!/bin/sh
export LIBRARY_PATH=/sw/lib:$LIBRARY_PATH
./Setup build
And then I ran
$ sudo ./script.sh
That compiled zlib without complaining - hooray! Unfortunately cabal-install is still giving me the error:
$ ./Setup configure
Configuring cabal-install-0.6.2…
Setup: At least the following dependencies are missing:
zlib >=0.4 && <0.6
So I went back to the cabal-install dir (which is what I'm trying to do in the first place), and ran...
$ ./bootstrap.sh
...and that installed everything as expected.
Why you use sudo ever? You should not compile as super user. Compile as normal user and install as super user.
Try setting LDFLAGS=-L/sw/lib.
GHC now comes with an installer for OS X (Leopard, not sure about Tiger). The only issue is that if you use macports or fink, these will probably not see that you have GHC installed and try to install their own version of it.

Resources