The bld.sh script provided installs gcc 4.8.4 and boost 1.57.0 on CentOS and Mac OS X for testing. It is another entry in my continuing series of releases for different versions of g++. Hopefully this will make it easier for folks that want to experiment with this version of the GNU C++ compiler to use C++-11 constructs.
There is also a very simple Makefile: http://projects.joelinoff.com/gcc/4.8.4/Makefile that is not required but that I found useful.
This text version is also available so that you can cut-n-paste from a web page: http://projects.joelinoff.com/gcc/4.8.4/bld.sh.txt.
Please note that this is not a product. It is simply my best attempt to get it working in my development environments. For example, it does not check for packages because I try to build it on different systems that have different package managers (yum, apt, port, etc.). What this means is that if it doesn’t work for you, you will have to do some debugging. If you find a problem, please post a fix in the comment section here so that others can benefit from it.
1 Download and Install It
Here are the steps to download and install it. Root access is not required unless you need to install support packages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ # Download and install it. $ mkdir /shared/tools/gcc/4.8.4 $ cd /shared/tools/gcc/4.8.4 $ wget http://projects.joelinoff.com/gcc/4.8.4/bld.sh $ chmod a+x bld.sh $ # Optionally there is also a very simple Makefile. $ wget http://projects.joelinoff.com/gcc-4.8.4/Makefile $ # bld.sh doesn't check for packages $ # This is one that I needed. $ # if not installed you will see a missing gnu/stabs-32.h error late in the process. $ sudo yum install -y glibc-devel.i686 <output snipped> $ # I also had to install texinfo, you may have to install others. $ sudo yum install -y texinfo <output snipped> $ # You can run bld.sh directly or you can simply type "make" if you downloaded $ # the Makefile. $ make |
The build process can take a long time depending on the speed of your CPU(s) and disks. On my test system it took several 5 hours.
If the process fails it is most likely because packages are missing on the system.
If a problem does occur, install the package, then delete the src and bld directories and try again. If you have installed the option Makefile you can type “make clean” and then “make”.
The rtf (release to field) directory contains the releases for each package.
2 How to Use the Compiler
This section shows how to compile, link and execute a simple program using the newly installed compiler by setting up your environment properly. This program is src/LOCAL-TEST/test4.cc and is used to test the installation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
// Example implementation of a quicksort that uses a number // of C++-11 constructs. #include <cassert> #include <algorithm> #include <chrono> #include <utility> #include <vector> #include <iostream> #include <random> using namespace std; template <typename T> auto insertionSort(vector<T>& a, size_t beg, size_t end) -> void { for(auto i=beg+1; i<=end; ++i) { // all items from beg to i-1 are sorted // insert the new one in the appropriate slot auto j = i; while (j>0 && a[j-1] > a[j]) { swap(a[j], a[j-1]); --j; } } } template<typename T> auto partition(vector<T>& a, size_t beg, size_t end) -> size_t { // Randomly select the pivot using a uniform distribution. random_device rd; mt19937 mt(rd()); uniform_int_distribution<size_t> dis(beg, end); auto idx = dis(mt); T pivot = a[idx]; swap(a[end], a[idx]); // reserve the end slot auto i = beg; for(auto j=beg; j<end; ++j) { // up to end - 1 if (a[j] <= pivot) { swap(a[i], a[j]); ++i; } } swap(a[i], a[end]); return i; } template <typename T, size_t M=32> auto quickSort(vector<T>& a, size_t beg, size_t end) -> void { if ((end - beg) < M) { insertionSort(a, beg, end); } else { auto pivot = partition(a, beg, end); if (pivot > beg) { quickSort(a, beg, pivot-1); // left } if (pivot < end) { quickSort(a, pivot+1, end); // right } } } auto test() -> bool { int M = 100000; // range of numbers in the array int N = 1000; // array size cout << "test" << endl; random_device rd; mt19937 mt(rd()); uniform_int_distribution<size_t> dis(1, M); vector<int> a; cout << "populating array with N=" << N << " where 1 <= a[i] <= " << M << endl; auto now = chrono::system_clock::now(); do { if (a.size()) { cout << "trying again - previous attempt was already sorted" << endl; } a.clear(); for(auto i=1; i<N; ++i) { int ran = dis(mt); a.push_back(ran); } } while (is_sorted(a.begin(), a.end())); auto end = chrono::system_clock::now(); auto ms = chrono::duration_cast<chrono::milliseconds>(end-now).count(); cout << "elapsed time: " << ms << "ms" << endl; cout << "sorting..." << endl; now = chrono::system_clock::now(); quickSort(a, 0, a.size()-1); end = chrono::system_clock::now(); ms = chrono::duration_cast<chrono::milliseconds>(end-now).count(); cout << "elapsed time: " << ms << "ms" << endl; cout << "testing..." << endl; cout << "STATUS: "; if (is_sorted(a.begin(), a.end())) { cout << "PASSED" << endl; return true; } cout << "FAILED" << endl; for(size_t i=0; i<a.size(); ++i) { cout << "a[" << i << "] = " << a[i]; if (i and a[i] < a[i-1]) { cout << " ** OUT OF ORDER - SHOULD BE EARLIER"; } cout << endl; } return false; } int main() { return test() ? 0 : 1; } |
You compile, link and run it as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/bin/bash # This script sets the environment to use the newly installed compiler. # It compiles, links and runs a small test program. # Setup the environment. MY_GXX_HOME="/shared/tools/gcc/4.8.4/rtf" export PATH="${MY_GXX_HOME}/bin:${PATH}" export LD_LIBRARY_PATH="${MY_GXX_HOME}/lib:${MY_GXX_HOME}/lib64:${LD_LIBRARY_PATH}" export LD_RUN_PATH="${MY_GXX_HOME}/lib:${MY_GXX_HOME}/lib64:${LD_LIBRARY_PATH}" # Compile and link. g++ -O3 -std=c++11 -Wall -o test.exe test.cc # Run. ./test.exe test populating array with N=100 where 1 <= a[i] <= 100000 elapsed time: 0ms sorting... elapsed time: 24ms testing... PASSED |
3 Disk Space Requirements
You will need about 5.5GB to download and build all of the packages. Once the build is finished you can reclaim most of the space because the released files only require about 600 MB. Here is the breakdown:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ # This was on my Mac $ cd /shared/tools $ du -s -h gcc/4.8.4 8.3G gcc/4.8.4 $ du -s -h gcc/4.8.4/* 190M gcc/4.8.4/archives 5.0G gcc/4.8.4/bld 28K gcc/4.8.4/bld.sh 17M gcc/4.8.4/logs 4.0K gcc/4.8.4/Makefile 1.2G gcc/4.8.4/rtf 2.0G gcc/4.8.4/src |
Note that the logs directory exists because I used the “make” command instead of running blds.sh directly.
Once it is built you can remove everything except the contents of the rtf directory tree to save disk space.
4 Packages
This is the list of packages that are installed in the release area.
Package | Version | Web Site |
---|---|---|
binutils |
2.24
|
http://ftp.gnu.org/gnu/binutils |
boost |
1.57.0
|
http://sourceforge.net/projects/boost/files/boost |
cloog |
0.18.1
|
http://www.bastoul.net/cloog”>http://www.bastoul.net/cloog |
gcc |
4.8.4
|
http://ftp.gnu.org/gnu/gcc |
gmp |
6.0.0a
|
http://gmplib.org/ |
libiconv |
1.14
|
http://ftp.gnu.org/pub/gnu/libiconv |
mpc |
1.0.2
|
http://www.multiprecision.org/mpc |
mpfr |
3.1.2
|
http://www.mpfr.org |
ppl |
1.1
|
http://bugseng.com/products/ppl |
5 Tested Platforms
These are the platforms that I actually tested the installation on.
Distro | Version | Arch | Status | Date | Notes |
---|---|---|---|---|---|
CentOS |
6.6
|
x86_64 | Passed | 2015-03-01 | Had to manually install the glibc_devel.i686 and texinfo packages. |
MAC OS X |
10.9.3
|
x86_64 | Passed | 2015-03-01 | Used macports for setting up the environment. |
Unfortunately, I do not have the bandwidth to try to get this to work on other distros (even though I have several Ubuntu boxes at hand) but it should be fairly straightforward to port because it does not rely on distro specific package management.
If you port it to another distro, please send me the changes to that I can incorporate them.
Enjoy!
I got this error during the compilation: (any idea)
cc1plus: error: unrecognized command line option “-Wno-overlength-strings”
make[3]: *** [build/genconstants.o] Error 1
make[3]: Leaving directory
/home/adminapp/apps/gcc-4.8.3/bld/gcc-4.8.3/gcc'
/home/adminapp/apps/gcc-4.8.3/bld/gcc-4.8.3′make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/adminapp/apps/gcc-4.8.3/bld/gcc-4.8.3′
make: *** [all] Error 2
STATUS = 2
Sorry about the delay, I have been out of town.
I know that this does not directly address the issue but I thought that this option was for C99 to catch strings longer than 4095. As far as I know, C++ does not have a limit on string length so removing it should have no affect.
What is your command line?
What is the setting of LD_LIBRARY_PATH? it is possible that you are using components from an older compiler for some reason
Are you specifying “-x c++” or compiling a C++ source file (i.e., *.cc)?
Do you have the output of a “-v” run? I would like to see what is going on in more detail.