Of course, the first question is: why I'm doing this. Just for fun! I'm learning more about Linux kernels and I have a virtual machine that I can replace in 15 minutes.

Getting to business, I don't know how to do this, so I went to trying to edit the makefile (trying to learn). So I started with the makefile in the path ubuntu-raring/Makefile, which is the main make file; can be found under this link:


And there I changed every gcc to icc, and every g++ to icpc, and every -O2 to -O3. The result is the following:


I followed the instructions from this site, too:


But eventually, I'm getting weird errors that seem to be caused by using gcc/g++ rather than icc/icpc. For example, I got an error in the file ubuntu-raring/include/linux/compiler-gcc.h that some macros are already defined, while this file shouldn't be included in the first place! The macro that includes it is in the file ubuntu-raring/include/linux/compiler.h, and looks like:

#ifdef __GNUC__
#include <linux/compiler-gcc.h>

/* Intel compiler defines __GNUC__. So we will overwrite implementations
 * coming from above header files here
# include <linux/compiler-intel.h>

And while I don't understand the comment written above the Intel header (sounds weird... why would you define implementations then overwrite them? Never done that in C++!), removing the include of the gcc header manually solved the problem, but other problems came up, and I have no idea whether they're related.

So now I'm confused! What did I do wrong? And should changing every gcc and g++ in the Makefile be sufficient to use a different compiler? Or are there other things to be changed that I overlooked?

Thank you for any efforts.

First learn to walk, then learn to fly.

If you want to learn, read. Have you read this instruction manual for building the kernel with the Intel C compiler? It's a rethorical question b/c this manual uses a different approach to choosing icc over gcc.

You are doing three things at once:

  • fiddle with some adopted and patched kernel to fit into the Ubuntu world (which is gcc)
  • Up the optimization from -O2 to -O3.
  • change the compiler

Start out with a vanilla Linux kernel from kernel.org. Keep everything standard and figure out how to build a kernel that works for your computer. Build a kernel that has only the drivers your computer needs, nothing more. Once you can compile and boot into your own kernel, you can start changing the build environment.

Going from -O2 to -O3 will probably never work. -O3 is like opening Pandora's box. If enabling -O3 was that easy, it would probably be the default!

  • Thank you so much. I will follow those instructions, and you get a +1, unless this is the best answer, then you get the big check mark soon :) – The Quantum Physicist Aug 31 '13 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.