Building GCC 8 on Chrome OS
Posted on October 5, 2017 by Paul
Updated 19 August 2018
This is a short introduction on how to build GCC 8 from sources on your Chromebook or Chrome OS device. I’ve tested the procedure on an Intel based Chromebook with 4GB of RAM. In principle, same approach should work on an ARM device. I assume that you’ve enabled the Developer Mode on your Chrome OS device.
In order to be able to build GCC 8, you will need a C++ compiler. You can install an older compiler toolchain from Chromebrew, for more details read my previous article or, if you prefer the short version, open a shell tab and write the next commands:
At this point, you should have GCC 4.9 installed on your machine. We will use the older 4.9 to compile GCC 8.
By default, Chrome OS marks /home/chronos/user/ as noexec, so you will get a Permission denied error if you want to run executable programs. AFAIK, there are two solutions. You can copy the executable to /usr/local/ or /usr/local/bin/. Alternatively, you can mark /home/chronos/user as exec with:
If you want to make your home directory exec permanent, save the above line at the end of your .bashrc file.
Binary version (Intel x86_64) if you don’t have the time and space for the actual build https://bitbucket.org/sol_prog/chrome-os-binary-x86-64
First, we will download GCC 8 and dependencies:
Next, we can start the actual compilation process which, depending on the speed of your machine, could take a few hours:
In order to be able to use GCC 8, you need to add it to your PATH:
If you want to permanently add the compilers to your system’s path, use the next commands:
If you need to compile a C++ file with GCC 8, don’t forget to append the -8.2 prefix, e.g.:
If you want to test the new compiler, you can use the next example. Open your favorite text editor and copy the next piece of code (I assume you’ll save the file as test_lambda.cpp):
The code uses a generalized lambda (we could use auto for the type of the parameters), this was introduced in the C++14 standard. We can compile and test the above program with:
If you are interested to learn more about the new C++ syntax, I would recommend reading The C++ Programming Language by Bjarne Stroustrup.
or, Professional C++ by M. Gregoire, N. A. Solter, S. J. Kleper: