Installing gcc 4.1.0 on ubuntu - gcc

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

Related

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

gcc unable to find shared library libisl.so

I installed gcc version 5.1 locally on a cluster having OS as CentOS where I dont have root access (so i cant use any commands like 'sudo'). (The global gcc version installed is 4.4). I also modified the path variable to include the path to my local version at the beginning of the path variable. Before, when I was trying to install boost using the global version, it worked fine. But now, when I try to install boost, it shows the following error:
/users/home/head/cmp/soft/sft/gcc/bin/../libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/cc1: error while loading shared libraries: libisl.so.10: cannot open shared object file: No such file or directory
Any ideas on how to fix this will be highly appreciated.
Follow the instructions at https://gcc.gnu.org/wiki/InstallingGCC
Specifically, don't install ISL manually in some non-standard path, because GCC needs to find its shared libraries at run-time.
The simplest solution is to use the download_prerequisites script to add the GMP, MPFR, MPC and ISL source code to the GCC source tree, which will cause GCC to build them for you automatically, and link to them statically.
I have the same issue. I solved it as follows:
Download the source code of isl available here
Unzip and install: ./configure && make && make install
cp /usr/local/lib/libisl* /usr/lib
Note: a symlink also works:
$ cd /usr/lib
$ ln -s /usr/local/lib/libisl.so.10 libisl.so.10
You can do the same in Debian distros:
apt-get install libisl-dev
Adjust the references of shared libs:
$ cp /usr/local/lib/libisl* /usr/lib
Note: a symlink also works:
$ cd /usr/lib
$ ln -s /usr/local/lib/libisl.so.10 libisl.so.10

GNU Linker equivalent command in OS X

I'm reading the following book about operating systems. In Page 43, they use the following command to convert annotated machine code into a raw machine code file:
$ ld -o basic.bin -Ttext 0x0 --oformat binary basic.o
When running that command in my MacBook Pro (running Mavericks), I get:
ld: unknown option: -Ttext
I've did some research and found out that OS X's linker doesn't allow using a script file as the linker script.
Some other posts on the internet recommend using the following "correct" format:
$ ld -T text 0x0 --o format binary -o basic.bin basic.o
Although it didn't work for me neither.
I also tried installing binutils via homebrew, but it doesn't seems to ship with GNU linker.
The command correctly runs in Ubuntu 14.04, but I'd like to continue developing in OS X if possible.
Is there a way to obtain the same results with OS X's linker, potentially with different flags?
UPDATE:
I was able to generate a bin with the following command, using gobjcopy from binutils:
$ gobjcopy -j .text -O binary basic.o basic.bin
However I couldn't find a way to offset label addresses in the code, as I could with GNU ld with -Ttext 0x1000 for example.
I tried with --set-start <hex> without any luck:
$ gobjcopy -j .text --set-start 0x1000 -O binary basic.o basic.bin
I am following the same os-dev.pdf guide and encountered the same problem as you.
The bottom of the issue is that we need to compile a cross-compiled gcc anyway, so the solution is just to do so.
There is a good guide at OSDev but if you're running a recent version of OSX I prepared a specific guide for this on Github
Here are the commands, though please test them before pasting the whole wall of text on your computer! At the Github link you will find the full explanations, but since Stack Overflow seems to like the solution embedded on the answer, here it is.
Also, if you encounter any error, please report it back to me (here or with a Github issue) so that I can fix it for other people.
brew install gmp
brew install mpfr
brew install libmpc
brew install gcc
export CC=/usr/local/bin/gcc-4.9
export LD=/usr/local/bin/gcc-4.9
export PREFIX="/usr/local/i386elfgcc"
export TARGET=i386-elf
export PATH="$PREFIX/bin:$PATH"
mkdir /tmp/src
cd /tmp/src
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.gz # If the link 404's, look for a more recent version
tar xf binutils-2.24.tar.gz
mkdir binutils-build
cd binutils-build
../binutils-2.24/configure --target=$TARGET --enable-interwork --enable-multilib --disable-nls --disable-werror --prefix=$PREFIX 2>&1 | tee configure.log
make all install 2>&1 | tee make.log
cd /tmp/src
curl -O http://mirror.bbln.org/gcc/releases/gcc-4.9.1/gcc-4.9.1.tar.bz2
tar xf gcc-4.9.1.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.9.1/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --disable-libssp --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
You will find GNU's binutils and your cross-compiled gcc at /usr/local/i386elfgcc/bin
manually install binutils always throw errors in my macOS.
The solution is to use homebrew:
brew tap nativeos/i386-elf-toolchain
brew install i386-elf-binutils i386-elf-gcc
then, you can use i386-elf-ld command instead of ld

Building the Go SWIG example code

I'm trying to build the example SWIG bindings that come with Go. The files I'm looking at are located in misc/swig/callback.
Are there instructions on how to build this example? I tried following the directions here:
http://www.swig.org/Doc2.0/Go.html
but the code generated by SWIG doesn't seem to compile with g++ (since it uses a C++ library ) and doesn't compile with g++ (with multiple compilation errors).
Has anyone built this example successfully?
Thanks!
For example,
$ export GOPATH=$HOME/gopath
$ cd $GOPATH/src/swig/callback
$ go clean
$ go install -v
swig/callback
$
Since you say you had problems with g++, do you have everything installed for g++? For example,
$ sudo apt-get install g++ g++-multilib libstdc++6
$ g++ --version
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3

How to install GCC piece by piece with GMP, MPFR, MPC, ELF, without shared libraries?

How do I install GCC (the GNU Compiler Collection) piece by piece, using the current version,
using the correct versions of dependencies, not using a package manager (like yum, rpm, apt, dpkg), and not using shared libraries?
Typical developers will likely want to install GCC the typical way, use your package manager (yum, rpm, apt, dpkg, port, brew, etc.) or follow the instructions here (http://gcc.gnu.org/wiki/InstallingGCC).
My question is how to install GCC piece by piece, without shared libraries.
I want a fully-independent GCC that can be moved around my system without using any shared libraries, and without creating any shared libraries.
This is what GCC calls "the difficult way" and it is not recommended for typical users.
GCC depends on:
GMP: GNU Multiple Precision Arithmetic Library
MPFR: GNU Multiple-precision floating-point rounding library
MPC: GNU Multiple-precision C library
ELF: Executable and Linkable Format library
PPL: Parma Polyhedra Library (optional, for memory optimizations)
The Easy Way
If you're a typical developer, you can install the easy way, using instructions at http://gcc.gnu.org/wiki/InstallingGCC or your system package manager such as:
apt install gcc # for Debian, Ubuntu, etc.
yum install gcc # for RedHat, CentOS, etc.
brew install gcc # for Mac OS X
The Hard Way
GCC says the answer here is "the hard way" because it builds everything piece by piece, and does not use shared libraries.
GCC infrastructure
Get the GCC infrastructure:
ftp://gcc.gnu.org/pub/gcc/infrastructure/
Put downloads in a temp directory (you can use whatever directory you want).
/opt/downloads
Build the infrastructure in a temp directory that is different than the downloads directory or its subdirectories:
/tmp/gcc
Configure the infrastructure using static libraries like this:
./configure --disable-shared --enable-static --prefix=/tmp/gcc
The --disable-shared flag may be worth a closer look depending on your needs. I use --disable-shared because I am building static code only, and I want to make sure that I don't build any shared code. My need is to move the resulting GCC around my drives easily, so I want all static code, and I do not want any shared code. If you prefer shared code, omit the --disable-shared flag.
Versions
When you run any of the commands in this answer, be sure to update the commands to use the current GCC version number that matches your needs. The commands in this answer are for GCC 4.6.2.
Note that the GCC documentation says: "While any sufficiently new version of required tools usually work, library requirements are generally stricter. Newer versions may work in some cases, but it's safer to use the exact versions documented."
GMP
GMP is the GNU Multiple Precision Arithmetic Library.
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
bunzip2 gmp-4.3.2.tar.bz2
tar xvf gmp-4.3.2.tar
cd gmp-4.3.2
./configure --disable-shared --enable-static --prefix=/tmp/gcc
make && make check && make install
MPFR
MPFR is the GNU Multiple-precision floating-point rounding library. It depends on GMP.
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
bunzip2 mpfr-2.4.2.tar.bz2
tar xvf mpfr-2.4.2.tar
cd mpfr-2.4.2
./configure --disable-shared --enable-static --prefix=/tmp/gcc --with-gmp=/tmp/gcc
make && make check && make install
MPC
MPC is the GNU Multiple-precision C library. It depends on GMP and MPFR.
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
tar zxvf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --disable-shared --enable-static --prefix=/tmp/gcc --with-gmp=/tmp/gcc --with-mpfr=/tmp/gcc
make && make check && make install
ELF
ELF stands for Executable and Linkable Format. This library provides architecture-independent size and endian support.
wget http://www.mr511.de/software/libelf-0.8.13.tar.gz
tar zxvf libelf-0.8.13.tar.gz
cd libelf-0.8.13
./configure --disable-shared --enable-static --prefix=/tmp/gcc
make && make check && make install
GCC
GCC is the GNU Compiler Collection. It depends on GMP, MPFR, MPC, and ELF.
wget http://www.netgull.com/gcc/releases/gcc-4.6.2/gcc-4.6.2.tar.gz
tar zxvf gcc-4.6.2.tar.gz
Build gcc in a scratch directory on the
same mount point. (Building it within /tmp would trigger cross compile host issues)
mkdir -p /opt/downloads/gcc-4.6.2-scratch
cd /opt/downloads/gcc-4.6.2-scratch
The configure command and its flags must be all on one command line (this post shows them on separate lines just because of web page width).
Note: We use the full path to configure and do not set library path environment variables. We choose to disable bootstrap and disable shared libraries because we don't want them (typical users may want both), and to use posix threads and to flags that are defaults because we want them (typical users may want to use other threads or skip default flags). YMMV and read about the flags here
/opt/downloads/gcc-4.6.2/configure
--disable-shared
--disable-bootstrap
--disable-libstdcxx-pch
--enable-languages=all
--enable-libgomp
--enable-lto
--enable-threads=posix
--enable-tls
--with-gmp=/tmp/gcc
--with-mpfr=/tmp/gcc
--with-mpc=/tmp/gcc
--with-libelf=/tmp/gcc
--with-fpmath=sse
make && make install
This page is great for GCC installation info, how to build it, various flags, and more:
http://www.acsu.buffalo.edu/~charngda/cc_build.html
Updates
The ppl libraries can be used for memory optimizations: see bugseng.com/products/ppl/Download (Thanks Paul in comments)
You could run ./contrib/download_prerequisites from the gcc source directory. (Thanks to N7P on reddit)
The accepted answer makes it far more complicated than necessary and is not correct for all versions. Building GCC with --disable-shared is usually a very bad idea. See http://gcc.gnu.org/wiki/InstallingGCC for an easier approach.
The entire process should be no more difficult than this (replacing 4.6.2 with the version you want to build):
tar xzf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.6.2/configure --prefix=$HOME/GCC-4.6.2
make
make install
(But please read the link above anyway, it contains useful information.)
Apparently some people on Ubuntu have tons of crap set in their environment which interferes with the GCC build process, and they need to remove that first:
unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE LD_LIBRARY_PATH
I work on a cluster. Only the master node is connected to the Internet. The software on nodes is outdated and generally not maintained. I don't have root access. I have two options:
build static software I need (computational packages); or
build static compilers.
I chose the second and built gcc, g++ and gfortran.
I built everything in
PREFIX=$HOME/cmp/soft/sft
and for make I used
THREADS=8
Below, gcc is built with
GMP
MPFR
MPC
ISL
CLOOG
One can get the latest gcc from here: ftp://gcc.gnu.org/pub/gcc/releases
Dependencies are found here: ftp://gcc.gnu.org/pub/gcc/infrastructure
Dependencies
I get dependencies with the following script:
#!/bin/sh
# ===========
## variables:
GMP=gmp-4.3.2.tar.bz2
MPFR=mpfr-2.4.2.tar.bz2
MPC=mpc-0.8.1.tar.gz
ISL=isl-0.12.2.tar.bz2
CLOOG=cloog-0.18.1.tar.gz
MIRROR=ftp://gcc.gnu.org/pub/gcc/infrastructure
# ===========
## functions:
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "I don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# ======================
## download and extract:
wget $MIRROR/$GMP
extract $GMP
wget $MIRROR/$MPFR
extract $MPFR
wget $MIRROR/$MPC
extract $MPC
wget $MIRROR/$ISL
extract $ISL
wget $MIRROR/$CLOOG
extract $CLOOG
The following bash function is used below:
mkdircd () { mkdir -p "$#" && eval cd "\"\$$#\""; }
Each of the commands below is to be issued in the dir of the lib just downloaded.
GMP
mkdircd build
../configure --disable-shared --enable-static --prefix=$PREFIX/gmp
make -j $THREADS && make check && make install
MPFR
mkdircd build
../configure --with-gmp=$PREFIX/gmp --disable-shared --enable-static --prefix=$PREFIX/mpfr
make -j $THREADS && make install
MPC
mkdircd build
../configure --with-gmp=$PREFIX/gmp --with-mpfr=$PREFIX/mpfr --disable-shared --enable-static --prefix=$PREFIX/mpc
make -j $THREADS && make install
ISL
mkdircd build
../configure --with-gmp-prefix=$PREFIX/gmp --disable-shared --enable-static --prefix=$PREFIX/isl
make -j $THREADS && make install
CLOOG
mkdircd build
../configure --with-gmp-prefix=$PREFIX/gmp --with-isl-prefix=$PREFIX/isl --disable-shared --enable-static --prefix=$PREFIX/cloog
make -j $THREADS && make install
gcc
mkdircd build
export LD_LIBRARY_PATH=$PREFIX/gmp/lib:$PREFIX/mpfr/lib:$PREFIX/mpc/lib:$PREFIX/isl/lib:$PREFIX/cloog/lib
export C_INCLUDE_PATH=$PREFIX/gmp/include:$PREFIX/mpfr/include:$PREFIX/mpc/include:$PREFIX/isl/include:$PREFIX/cloog/include
export CPLUS_INCLUDE_PATH=$PREFIX/gmp/include:$PREFIX/mpfr/include:$PREFIX/mpc/include:$PREFIX/isl/include:$PREFIX/cloog/include
../configure --with-gmp=$PREFIX/gmp --with-mpfr=$PREFIX/mpfr --with-mpc=$PREFIX/mpc --with-isl=$PREFIX/isl --with-cloog=$PREFIX/cloog --disable-shared --enable-static --disable-multilib --prefix=$PREFIX/gcc --enable-languages=c,c++,fortran
make -j $THREADS bootstrap && make install
Used what Jonathan above has mentioned except that I had to download gmp and mpfr manually and create soft link (gcc 4.4.2 distribution probably does not have "download_prerequisites")
cd src/gcc-4.4.2
ln -s ~/linux64/gmp-4.2.1 gmp
ln -s ~/linux64/mpfr-2.3.0 mpfr
Btw, using "-with-gmp" and "with-mpfr" with "./configure" gave me "configure: error: cannot compute suffix of object files: cannot compile". Hence I downloaded the srcs of gmp and mpfr and then created the soft link to it from within gcc src top leve dir
After trying to install GCC dependencies including GMP, MPFR and MPC. I ran into additional install requirements, Errors and missing files; such as gmp.h header file required by MPFR to install. There are quit a number of issues you will run into in the process. However, There is an Easier way to Build and Install GCC-X.0.0 or later version with an automatic linking.
OPTION ONE.
To save the trouble of Building with make, make install and Linking the dynamic libraries, Simply:
Download your GCC-X.0.0 -version (with latest version from: https://gcc.gnu.org/)
Extract the gcc-X-000.tar.gz files to a location /somepath/.
Once you have Extracted .tar.gz file, run ./contrib/download_prerequisites script which is located on /somepath/ or the source directory.
This script will download support libraries including: GMP, MPFR and MPC and will create a Symlinks for you, that will BUILD all gcc dependencies automatically as part of gcc Installation process.
No need to Build and Link support libraries that were downloaded to /somepath/ by issuing Make, Make Install or running ./configure file or adding links such as --with-gmp=/gmp_path/.../....., --with-mpfr=/mpfr_path/.../... because this was done when you ran script that created symlinks.
OPTION TWO.
Use your OS Package management system to install the support libraries in standard system location. For Debian based system including Ubuntu, Install libgmp-dev, libmpfr-dev and libmpc-dev packages. For RPM based system including Fedora and SUSE, install gmp-devel, and libmpc-devel(mpc-devel on SUSE) packages.
This option will install libraries and header files in a standard system directory where they will be found automically when building GCC.
This is the advantage of OS Package installation Management when you invoke "sudo apt-get install libgmp-dev" or "sudo apt-get install libmpfr-dev" install and linking is done for you. In addition, you don`t have to build the support libraries with Make, Make install or ./configure. Plus, the process takes a few minutes to complete the all process.
Now you can proceed on with GCC Installation.
CONFIGURATION:
This is the GCC config Process, with gcc-X-000.tar.gz
Issue:
tar -xvf gcc-X-000.tar.gz
cd gcc-X-000
./contrib/download_prerequisites
cd ..
mkdir objdir
/../gcc-X-000/configure --prefix=$HOME/gcc-X-000 --enable-languages=c,c++,fortran,go --disable-multilib
make -j 2
make install
NB:
--enable-languages such as c++ or c.
--disable-multilib; disable multilib based on your system and OS, you will be prompted about multilib to proceed.
Make will take long time to complete. However, you can issue the option -j #no_pro. This will run Make concurrently in parallel based on the number of processors on your PC or Mac.
For detailed information on how to execute this process you can visit:
https://gcc.gnu.org/wiki/InstallingGCC.
I followed the top accepted answer by joelparkerhenderson. This is the best answer that I could find for installing on a *NIX system over the internet.
For posterity I want to add that if you get an error like
"install error: cannot compute suffix of object files: cannot compile"
then update your LD_LIBRBARY_PATH with /tmp/gcc/lib (See joelparkerhenderson's full answer for context)
/tmp/gcc/lib contains all the required mpfr/mpc/gmp so files and the run time linker cannt find them unless you add them to LD_LIBRARY_PATH. Also dont forget to export LD_LIBRARY_PATH ;). More context here: https://gcc.gnu.org/wiki/FAQ#configure_suffix

Resources