How to compile GCC Cilkplus ?

How to compile GCC Cilkplus ?

Hi everyone,

I am trying to compile my first line of Cilk language with GCC...

I have "checkouted" the specific branch of GCC :

And then i ran :
make install

And now my compiler version (gcc -v) is now : 4.7.0
(I am using Ubuntu x64)

But I don't know how to compile a simple cilk file!!
What is the command line I should use to compile a Cilk file ?

Thank you very much

22 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The compiler you just built should be able to recognize the Intel Cilk Plus keywords. Try compiling a simple program like fib. For example:


int fib(int n)
  int x, y;

  if (n < 2)
    return n;

   x = cilk_spawn fib(n-1);
  y = fib(n-2);
  return x+y;

int main(int argc, char **argv)
  int n = 30;
  printf("fib(%d): %d\n", n, fib(n));
  return 0;

Compile this just like you'd compile any C or C++ program. cilk.h provides "nice" macros for the Cilk keywords. You could use _Cilk_spawn and _Cilk_sync instead if you chose.

- Barry

Thank you for your help
When i try to compile the file I get this error message :
g++ test3.cpp -lcilkrts
In file included from test3.cpp:1:0:
/usr/local/include/cilk/cilk.h:42:25: erreur fatale: cilk-sysdep.h : Aucun fichier ou dossier de ce type
compilation termine.
and the same error with this command line :
g++ test3.cpp

(My sytstem is in French, this is the translation :
g++ test3.cpp -lcilkrts
In file included from test3.cpp:1:0:
/usr/local/include/cilk/cilk.h:42:25: fatal error : cilk-sysdep.h : no file or directory of this type
compilation ended

I have tried this :
locate cilk-sysdep.h
And here is the result :

What do you think about it ?
Do I need to re-install GCC ?
If yes, can you help me with this step which is quite new for me :) ?

In fact my question is :
What is the good process to have GCC able to compile Cilk language on a Ubuntu x64 machine ?

cilk.h should contain a header and the following code:

/* Define convenient aliases for Cilk keywords */

#ifndef cilk_spawn
# define cilk_spawn _Cilk_spawn
# define cilk_sync  _Cilk_sync
# define cilk_for   _Cilk_for

You appear to have multiple copies of cilk.h on your system. Have you installed Cilk++ previously? Can you uninstall the old version(s)?

- Barry

Yes i have installed cilk++ previously !
But how to uninstall it properly ??

Thank you again for your help !

It's ok !
Now I have uninstalled cilk++ !

And now when I try to compile the code you gave to me i got this :
"test3.cpp:1:23: erreur fatale: cilk/cilk.h : Aucun fichier ou dossier de ce type
compilation termine."

In english now :
"test3.cpp:1:23: erreur fatale: cilk/cilk.h : No file or directory
end of compilation"

Hello MrJay42,
Please download this snapshot (;a=snapshot;h=90e7cf8c6f8bb1ad957f3bc5f8bdbb0809581074;sf=tgz) for the latest compiler.

From what you tell me, either the library path is not set correctly and/orsome files are getting deleted from thelibcilkrts directory. At the end of this post, i have posted a detailed tutorial that explains how to build the compiler correctly.

Couple comments about your post.... when you build GCC (or any GNU tools) please donot just type ./configure, please create a build directory to store object files and configure inside it(I have mentioned how to do it in the tutorial below). Sometimes the configure script can delete certain files, and if you do it in source directory, it can delete some important files.Also, if you do not provide a target directory(indicated using --prefix=..), when you type make install, it willremove (if you have sudo/admin power) existing GCC Compiler in your machine.


Balaji V. Iyer.

Here is the tutorial:

1.Download the gcc sources and save it in a directory called $HOME/gcc-4.7. The final compiler executables and the appropriate libraries will be stored in $HOME/cilkplus-install .

2.Copy the gmp, mpc and mpfr directories to the $HOME/gcc-4.7/ directory.

3.Create a new directory called "b-gcc" under $HOME/ . This directory will hold all the object files. You may delete this directory after the successful completion of all the steps in this tutorial.

4.Go to the b-gcc directory and type the following command:

$HOME/gcc-4.7/configure --prefix=$HOME/cilkplus-install --enable-languages="c,c++"

The above command will configure the compiler makefiles to set the install directory to be $HOME/cilkplus-install and build just the C and C++ compilers.

5.Type "make" in the same directory. This command will build the compiler sources. This will probably take quite a while.

6.Type "make install" . This command will copy the compiler executables and the required libraries to the install directory.

The compilers (g++ and gcc) should now be in the $HOME/cilkplus-install/bin directory.

To use the GCC Cilk Plus compiler, it needs to be in your PATH and the libraries need to be in your LIBRARY_PATH and LD_LIBRARY_PATH. The following commands can be used (in a BASH Shell) to accomplish this:

export LD_LIBRARY_PATH=$HOME/cilkplus-install/lib

export LIBRARY_PATH=$HOME/cilkplus-install/lib

Building a Cilk Plus application with the GCC compilers requires explicitly linking with libcilkrts, and libdl. For example:

$HOME/cilkplus-install/bin/gcc -ldl -lcilkrts

$HOME/cilkplus-install/bin/g++ -ldl -lcilkrts

Wow thank you very much this is perfect !!

Some questions before starting this tutorial :
I would like to be sure that i have uninstalled the previous installation of GCC !
I dont know the command to uninstall GCC in a clean way.
How can I do that ?

You tell me to copy the gmp and mpfr direcories to a new one...
But I dont know how to find these directories, and I don't know which one to copy !
Am I obliged to copy these directories ? : I know that gmp and mpfr are installed because I installed them before starting to compile and install GCC

I am so sorry for being so nooby...I hope that then I will be able to help other people with Cilk installation !

Thank you again for your help :)

Hello MrJay42,
You have to download, GMP, GPC and MPFR (Please google them and you can find them). After that please unzip the files and then store it in $HOME/gcc-4.7/gmp $HOME/gcc-4.7/gpc and $HOME/gcc-4.7/mpfr directories.Newer versions of GCC(not aCilkPlus requirement, but GCC in general requirement)requires you to downloadthese packages (4.2.4 I think did not require these).

Now, to remove the old Cilk++ compiler, if you build it from source and you did NOT use a prefix command when you configured and then typed "make install" you may have overwritten the host GCC. The only way to fix it is to delete the GCC and G++ in /usr/bin and all the supporting packages in /usr/lib (please be careful and check with a sys-admin before you startrandomly deleting files. If not done correctly, it can damage your system). After you delete that GCC, reinstall GCC in your system using yum (if redhat) or apt-get install (if Ubuntu).

If you DID use a prefix, then just delete everything in that directory (e.g. if you have ../gcc/configure --prefix=/tmp/install, then delete the /tmp/install directory).

I hope this helps.


Balaji V. Iyer.

Ok, now, thanks to you I have all the element to install correctly GCC cilkplus branch :)

I will take my time and carefully make each step then I will post here some news !

Now I have uninstalled gcc-4.7.0. I know that because know when I type "gcc -v" I have the "old" 4.5.2 :)
To be sure I reinstalled it via apt-get.

Then I have downloaded GMP, MPFR and GPC

I downloaded GMP from this link :
I downloaded MPFR from this link :
I downloaded GPC from this link :
(I hope that I have taken the right thing to download !!)

Then I have "unziped" each archive, taken all the files and put them into three directories :
This directories I will copy into the directory where i have "checkouted" GCC cilkplus branch

Is it ok ?

Yes, the steps you mentioned sound correct.


Balaji V. Iyer.

Ok so I have followed the step VERY carefully
And it is still not working.

Here are the details :
At the end of the make step
it says :
make[3]: *** [cp/parser.o] error 1
make[3]: leaving directory /home/mrjay/b-gcc/gcc
make[2]: *** [all-stage1-gcc] error 2
make[2]: leaving directory /home/mrjay/b-gcc
make[1]: *** [stage1-bubble] error 2
make[1]: leaving directory /home/mrjay/b-gcc
make: *** [all] error 2

And also there is one warning that appear all along the make process :
cc1: warning: unrecognized command line option "-Wno-narrowing"

And of course make install crashes also :
make[1]: entering the directory /home/mrjay/b-gcc
/bin/bash /home/mrjay/gcc-4.7/mkinstalldirs /home/mrjay/cilkplus-install /home/mrjay/cilkplus-install
/bin/bash: ligne 3 : cd: ./fixincludes: no file or directory of this type
make[1]: *** [install-fixincludes] error 1
make[1]: leaving directory /home/mrjay/b-gcc
make: *** [install] error 2

I am so sorry for upping my topic that often...
I think that now I am not far from the end of this least I hope so :)

It seems that the problem is related with the directories...and that the make install does not know where to find a directory or a file...

What do you think about this ??

Hello MrJay42,
What error are you getting in cp/parser.o (It should be printed right before the make[3]: ***)?

Did you download the gcc from thesnapshot link I gave you? From what you tell me, it looks like you used a version that is newer than the snapshot I gave you. I am currently in the process of fixing the bugs inthe newer version(it takes a while for my submission to reflect into the GCC website).

Also, if make gives error, make install will surely give error, so it is not necessary to try it.


Balaji V. Iyer.

Ooops I did not see the snapshot !
I was using this branch :
as a classic svn branch : svn co and then svn update each time I need it to be sure that it was up to date.

I am downloading the snapshot right now : i will try again the procedure with the snapshot.
(as I live in Finland it s a bit late now, so maybe I will try this tomorrow, moreover because the snapshot download seems to be long)

For the errors if they appear again, I will copy/paste them here :).
But right now I have closed the terminal that contained the errors :)

Once again, thank you very much for your help !

I think the snapshot should work fine. If you have further problems, please feel free to contact us again.


Balaji V. Iyer.

Finally, I wanted to test as soon as possible, and it does not work :
I have followed the steps from the tutorial
I have used the snapshot sources

Here are the error givent by the "make" command :
# multilibs.
/home/mrjay/b-gcc/./gcc/xgcc -B/home/mrjay/b-gcc/./gcc/ -B/home/mrjay/cilkplus-install/x86_64-unknown-linux-gnu/bin/ -B/home/mrjay/cilkplus-install/x86_64-unknown-linux-gnu/lib/ -isystem /home/mrjay/cilkplus-install/x86_64-unknown-linux-gnu/include -isystem /home/mrjay/cilkplus-install/x86_64-unknown-linux-gnu/sys-include -g -O2 -m32 -O2 -I. -I. -I/home/mrjay/gcc-4.7/gcc -I/home/mrjay/gcc-4.7/gcc/. -I/home/mrjay/gcc-4.7/gcc/../include -I/home/mrjay/gcc-4.7/gcc/../libdecnumber -I/home/mrjay/gcc-4.7/gcc/../libdecnumber/bid -I../libdecnumber -I/home/mrjay/gcc-4.7/gcc/../libgcc -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -I. -I. -I../../.././gcc -I/home/mrjay/gcc-4.7/libgcc -I/home/mrjay/gcc-4.7/libgcc/. -I/home/mrjay/gcc-4.7/libgcc/../gcc -I/home/mrjay/gcc-4.7/libgcc/../include -I/home/mrjay/gcc-4.7/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o _muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep -DL_muldi3 -c /home/mrjay/gcc-4.7/libgcc/../gcc/libgcc2.c \
-fvisibility=hidden -DHIDE_EXPORTS
In file included from /usr/include/bits/errno.h:25:0,
from /usr/include/errno.h:36,
from /home/mrjay/gcc-4.7/libgcc/../gcc/tsystem.h:94,
from /home/mrjay/gcc-4.7/libgcc/../gcc/libgcc2.c:29:
/usr/include/linux/errno.h:4:23: erreur fatale: asm/errno.h : No file or directory of this type. End of compilation
make[5]: *** [_muldi3.o] Error 1
make[5]: leaving directory /home/mrjay/b-gcc/x86_64-unknown-linux-gnu/32/libgcc
make[4]: *** [multi-do] Error 1
make[4]: leaving directory /home/mrjay/b-gcc/x86_64-unknown-linux-gnu/libgcc
make[3]: *** [all-multi] Error 2
make[3]: leaving directory /home/mrjay/b-gcc/x86_64-unknown-linux-gnu/libgcc
make[2]: *** [all-stage1-target-libgcc] Error 2
make[2]: leaving directory /home/mrjay/b-gcc
make[1]: *** [stage1-bubble] Error 2
make[1]: leaving directory /home/mrjay/b-gcc
make: *** [all] Error 2

Just in case here is my "uname -a "...I dont if it can help... :
Linux mrjay-PC 2.6.38-12-generic #51-Ubuntu SMP Wed Sep 28 14:27:32 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
As you can see my computer is in 64bits :)

There could be 2 issues from what I can tell....

1) You maybe missing multilib. If so, then when you configure, add the following tag: "--disable-multilib"

2) If 1) doesn't work, then it looks like some of your host include files have some problem... I think the only way to fix this is to re-install the host gcc in your machine.


Balaji V. Iyer.

I have uninstalled everything related to gcc
And then I have reinstalled it

Now I am waiting for the "make" to finnish...
I hope It will work

Ok, It works perfectly, I have compiled my first file coded in Cilk :)

Thank you very much for your help !
Now I can show off in the street with my new tee-shirt : "I compile Cilk code"

I have written a little tutorial that embed all the things that have been said on this thread.
Here it is :

General idea :
1. Download the good version of the GCC sources 4.7.0 on the GIT of GCC : branch "cilkplus"
2. Download all the libs that are needed and put them into the directory "checkouted" from the branch
3. configure, make, make install

Detailed procedure :

1. create a new directory : $HOME/cilkplus-install
1a. create a new directory : $HOME/gcc-4.7
1b. Download this snapshot of the GCC branch :;a=snapshot;h=90e7cf8c6f8bb1ad957f3bc5f8bdbb0809581074;sf=tgz
The archive will be named in a bad it just test.tgz and extract it here : $HOME/gcc-4.7

2. Download the libraries needed for GCC to be compiled !
GMP from this link :
MPFR from this link :
GPC from this link :
You have to download the source, and put each of this into a directory in the gcc-4.7 directory, in order to have this :$HOME/gcc-4.7/gmp/
3. Create a new directory $HOME/b-gcc

4. Open a terminal go to $HOME/b-gcc

5. One you are in b-gcc directory : type this command : $HOME/gcc-4.7/configure --prefix=$HOME/cilkplus-install --enable-languages="c,c++"

6. If everything is ok, go to step "7"
6a. if not try typing this : $HOME/gcc-4.7/configure --prefix=$HOME/cilkplus-install --enable-languages="c,c++" --disable-multilib
and then go to step "7"

7. (still in the b-gcc directory) type "make" and wait. (It will take at least 1 or 2 hours depending on the machine...On my Quad Core it has taken more than 1 hour (!!))
Don't worry about the warnings during the "make" process...

8. If there are no errors at the end of the "make" proces then you can type "make install"
You will find the executable in this directory : $HOME/cilkplus-install/bin

9. Here is a sample code that compiles after the installation, you can copy it, and put it into a file called "test.cpp" :

int fib(int n)
int x, y;

if (n < 2)
return n;

x = cilk_spawn fib(n-1);
y = fib(n-2);
return x+y;

int main(int argc, char **argv)
int n = 30;
printf("fib(%d): %d\n", n, fib(n));
return 0;

10. how to compile test.cpp ?
Type these commands in a terminal (you can work now into your favorite directory where you have put "test.cpp")

export LD_LIBRARY_PATH=$HOME/cilkplus-install/lib

export LIBRARY_PATH=$HOME/cilkplus-install/lib

$HOME/cilkplus-install/bin/g++ -ldl -lcilkrts test.cpp

And you are DONE, you can execute the file "a.out" by typing : ./a.out

10a. Generic command to compile

$HOME/cilkplus-install/bin/gcc -ldl -lcilkrts

$HOME/cilkplus-install/bin/g++ -ldl -lcilkrts

Glad to hear things worked out for you!

Thank you for writing a detailed tutorial for the future users.

Yours sincerely,

Balaji V. Iyer.

The git repo link posted in step 1b didn't work with wget on my Linux server so I tried a browser from a Win7 laptop. After pulling down a 94MB file the NOD32 antivirus kicked in to scan it and found "Archbomb.ZIP trojan". A little strange and probably user error on my part. Just FYI.

Hello District9,
If you would like, you can downloadthe latestsnapshot from GCC repository (;a=shortlog;h=refs/heads/cilkplus)... I tried it and it seems to download OK.


Balaji V. Iyer.

P.S. If you are familiar with git, you can download the GCC sources using GIT, so that you can track all the changes that users contribute.


Balaji V. Iyer.

Leave a Comment

Please sign in to add a comment. Not a member? Join today