Intel C++ Compiler

Intel's C/C++ compiler, icc, can be used as an alternative to GNU's compiler, gcc. The main benefit of using icc instead of gcc is its ability to optimize, especially for Intel CPUs. The main downside to using icc is its incompatibility with some code written specifically with gcc in mind. For instance, sys-libs/glibc and other system critical components cannot be compiled with icc. It is not possible to completely replace gcc with icc at this time. After following this guide, your system will still compile packages with gcc by default. Only prespecified packages will be compiled with icc.

dev-lang/icc is available through Portage. It does, in fact, require a license, but a free non-commercial license is available.

Just because you don't own an Intel CPU doesn't mean this HOWTO doesn't apply to you. With a bit of reverse engineering (not on our part), and a clever Perl script, we can make icc produce lovely machine code for AMD CPUs also.

Binaries compiled with icc won't work after icc is uninstalled
Binaries compiled with icc are dynamically linked to icc libraries. Therefore, if icc is uninstalled, binaries compiled with icc will not work. Before uninstalling icc, all binaries compiled with icc should be recompiled with gcc.

icc cannot compile all packages in Portage
icc and gcc have different levels of tolerance in what code is considered valid. Some packages have been written using gcc-specific extensions cannot be compiled with icc. Compilation of these packages using icc will result in a compile error. System critical components should not be compiled with icc. If glibc is miscompiled (e.g., in a way different from how gcc would compile it) it could render the system useless.

Critical system packages that should not be compiled with icc are

app-shells/bash sys-apps/sed sys-devel/binutils sys-devel/gcc sys-libs/glibc sys-libs/ncurses sys-libs/libstdc++-v3 sys-libs/zlib sys-process/procps

Installation
Simply emerge it.

You also need to get a license. For the purposes of this guide, we'll get a free non-commercial license. Click 'Free non-commercial Download' on Intel's Linux Compiler page or visit Intel's Non-Commercial Software Download page. Follow the steps on the site and place your license file in.

Upgrade to Intel® Composer XE (including ICC 12.0)
Intel C compiler is no longer available as single software, recently it was merged into software Intel® Composer XE (which consists of Intel® C++ Composer XE, Intel® Fortran Composer XE). If you want to upgrade, you need to download Intel® Composer XE from here, manually install it (Intel composer and Intel C Compiler libraries are not fully compatible, so do not try to overwrite them). After the installation, you may want to replace older binaries with newer ones (add newer to $PATH), to do this add this line to the end of your bashrc file:

If you want to remove old Intel C Compiler, you (probably) have to rebuild all packages with either GCC or newer ICC included in XE and then you are safe to unmerge it. Easiest way how to upgrade ICC is use layman repository bicatali], however this is unsupported repository and early e-build of this package unmerged original ICC and often crippled system that used ICC libraries in critical packages (fixed within week using SLOT).

/etc/make.conf
Add your icc CFLAGS to /etc/make.conf. See discussion of icc specific CFLAGS later.

/etc/portage/bashrc
/etc/portage/bashrc will tell Portage which compiler to compile a package with.

Here's another version of a working /etc/portage/bashrc. Use this one, if you want to use icc by default and just switch to gcc where necessary by adding those packages to /etc/portage/package.gcc.

/etc/portage/package.icc
/etc/portage/package.icc will store the names of all the packages that should be compiled with icc. If a package is not listed in this file, it will be compiled with gcc.

Here's a list of packages that work well with icc.

/etc/portage/package.icc-cflags
/etc/portage/package.icc-cflags provides per-package CFLAGS for packages compiled with icc. A few packages benefit greatly from the -O3 flag. Put them in this file.

Note: Since later flags override first declared flags, the deltas are now sufficient, as they are imported after ICCCFLAGS in the bashrc -- h0ru5 22:44, 19 August 2011 CET

Note: compiling dev-lang/python with the -O3 flag in icc 10.0 is confirmed to break .find in python according to issue 1084, which may result in emerge becoming unusable. Use this flag with extreme caution.

Note: After icc version 10.0.008 the issue with .find has been fixed. Really? find doesn't work with icc 10.0.026 --Icorey 21:01, 19 July 2009 (GMT)

/etc/portage/package.gcc-cflags
The /etc/portage/bashrc file even allows us to have per-package CFLAGS for gcc too. Add your packages and CFLAGS to /etc/portage/package.gcc-cflags in the same format as /etc/portage/package.icc-cflags.

Finishing up
After you've created/edited these files remember to run

icc CFLAGS
For a complete list of icc CFLAGS, check

icc supports many of the same CFLAGS as gcc, so many should look familiar. It is also very forgiving. That is, if a package passes a CFLAG to icc that it doesn't recognize, it will warn and move on.

-Ox
Same behavior as gcc. x is one of the following options


 * 0 - disables optimizations
 * 1 - enables basic optimizations
 * 2 - enables more optimizations (the default behavior)
 * 3 - enables the more aggressive optimizations that may or may not improve performance (recommended for math intensive looping programs)
 * s similar to -O1, with more of a bias toward smaller binaries

-xX
To specify a specific processor type to optimize for, pass -xX where X is one of the following options.

K - Generate SSE code W - Generate SSE2 code P - Generate SSE3 code T - Generate SSSE3 code S - Generate SSE4 code SSE3_ATOM - Generate SSE3 code for Intel Atom

The -x CFLAG generates specialized code to run exclusively on processors indicated by X. To generate generic code in addition to specialized code, use -axX where X is one of the previous options.

-ip[o]
The -ip flag enables Interprocedural Optimizations such as function inlining, dead code elimination, etc. This flag is recommended, but may not work with all packages. If a package is found that does not compile with this flag, add the package and its CFLAGS minus -ip to packages.icc-cflags.

The -ipo flag enables multifile Interprocedural Optimizations. Many packages do not compile with this flag. Add a package to package.icc-cflags with CFLAGS including -ipo to test.

-gcc
The -gcc CFLAG causes icc to generate code compatible with gcc. This is highly recommended, especially for libraries.

Uncripple icc on AMD CPUs
icc generates code that detects the brand of processor on which it is executing. On Intel CPUs, the binary will execute with SSE instructions, whereas it will execute 386 level instructions on AMD CPUs regardless of availability of SSE instruction sets.

To make icc produce binaries that execute SSE code on AMD CPUs, use the patches found here. Use the patches that patch the compiler. It's not clear if this is a violation of the EULA, so do it at your own risk. Otherwise, you can manually patch all icc produced executables. To patch, run the Perl script found on the said website in the lib/ directory of your icc installation. It's usually.

Another utility called `patch-AuthenticAMD' does the same, i.e. patch binaries generated by the Intel C++ compiler to get maximum performance on AMD CPUs. It can be found here.

System cannot boot due to missing icc libraries
icc is installed to /opt. If /opt happens to be on a different partition than the root partition, any system tools needed to boot the system will not function before /opt is mounted. For instance, if /bin/mount has been compiled with icc, it will be unable to execute which prevents any other partitions from mounting.

The solution is to copy the icc libraries to /lib.

C compiler cannot create executables
Your license file probably cannot be found. Try to execute

It will tell you if this is the case. If it is not, double check your CFLAGS.

The portage sandbox can also cause this message. If you can run icc from the shell but emerges will fail because icc can not be found e.g. in the configure phase, then add the aforementioned line from /etc/bash/bashrc to /etc/portage/bashrc. -- h0ru5

Could not open source file limits.h
When compiling programs whose source include limits.h, you may encounter the following error.

/usr/include/gentoo-multilib/amd64/limits.h(125): catastrophic error: could not open source file "limits.h"                         ^
 * 1) include_next 

A fix has been found, but it has not been thoroughly tested.

Mixed success is experienced when compiling PHP with dev-lang/icc-10.1.017 or later without this fix.

Linking fails with Qt
icc version 10.1.017 reorders arguments to the linker, breaking the compilation of Qt-4.3.3. As an example the option -Qoption,ld,--dynamic-list,src/gui/QtGui.dynlist is split so that the argument to --dynamic-list does not appear immediately after it. As a work-around, obtain a trace using strace -o log -F -f -s 4000 and re-order the arguments to ld and run the command manually.

Links

 * Older Support Thread on the Gentoo Forums [locked]
 * Support for HOWTO: Intel C++ Compiler/per-package CFLAGS

Intel C++ Derleyicisi