I have just been painfully discovering that gcc apparently generates -fpic code by default and links with -fPIE by default (On ubuntu 17.04). This completely screws up thousands of tests I run with scripts and makefiles used by lots of different linux distros. Is there any global or per-user way to turn off these defaults and make the compiler backward compatible with the behavior it has had for decades? I'm not interested in tracking down every compilation in thousands of scripts that knows the default is not -fpic, etc. An environment variable or two perhaps?
Ubuntu – Disable PIE and PIC defaults in gcc on ubuntu 17.04
gcc
Related Solutions
Install a helpful tool
checkinstall
sudo apt-get install checkinstall
Download the source package here, e.g.
cd wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
Extract the archive
tar xf gcc-5.2.0.tar.bz2
Install some development packages
sudo apt-get install libgmp-dev sudo apt-get install libmpfr-dev sudo apt-get install libmpc-dev
Go into the source folder
cd gcc-5.2.0
Configure, in my example a 64-bit-only compiler (
--disable-multilib
), for 32-bit and 64-bit support use--enable-multilib
./configure --disable-multilib
Start the compiler and drink a coffee or two ;) This step takes some time.
make
Install
sudo checkinstall
You could also use
sudo make install
, but withcheckinstall
you will have an installed deb package.
... which was running for almost half an hour and made a directory as big as 1 GB. So I doubted the source file and interrupted it.
It's possible that you're on the right track, and rushed into stopping the build prematurely. Depending on the strength of your machine, 30 minutes doesn't sound unreasonable time for building GCC. Most importantly, you're building using make
, which means that source files are compiled serially, one at a time, which is make's default. For speeding up the build significantly, run make -j
, which will build parallely using all CPU cores, or make -j4
for running 4 parallel compile jobs, for example.
As for build size, I suspect that by default, GCC builds in Debug mode, which would explain the bloated build folder (for comparison, LLVM debug build could easily stack up to > 4GB).
However, if you don't have to build your own copy of GCC from source, you could use pre-built 5.4 packages available on Launchpad.
For GCC (C only), grab the .deb files and install them in order:
mkdir ~/Downloads/gcc-5.4-deb && cd ~/Downloads/gcc-5.4-deb
wget http://launchpadlibrarian.net/375474546/gcc-5-base_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474798/libasan2_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474828/libmpx0_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474805/libgcc-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474748/cpp-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474755/gcc-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i gcc-5-base_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libasan2_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libmpx0_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libgcc-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i cpp-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i gcc-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
For C++ support, add the following:
wget http://launchpadlibrarian.net/375474836/libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474834/libstdc++-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474751/g++-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libstdc++-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i g++-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
Do note that, downgrading libstdc++6
may cause breakage of some packages (for example, cmake
and firefox
on my Ubuntu 18.10). Keeping multiple libstdc++'s is technically possible, but difficult to accomplish and surely not ideal.
Best Answer
I had the same problem and just solved it thanks to this post on Stack Overflow.
You should add
-no-pie
option to compilation command linewithout:
with: