1

I need to use the cilk plus annotations in my C++ program, something like:

#inlcude <cilk/cilk.h>

cilk_spawn myFunction();
cilk_sync;

I'm using JetBrains CLion IDE and I'm getting the error Error after macro substitution: can't resolve type '_Cilk_spawn'. I'm wondering whether there is any solution. Of course, using g++ straight from my terminal, i simply add the option -fcilkplus, but in this case I don't know how to solve this problem. Here is the content of my CMakeLists.txt file (updated):

cmake_minimum_required(VERSION 3.8)
project(C__Threads)

set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
set(CMAKE_CXX_FLAGS "-fcilkplus") // I've also put this one because otherwise the building process fails.

add_executable(C__Threads ${SOURCE_FILES})
target_compile_options(C__Threads PUBLIC -fcilkplus)
set(CMAKE_VERBOSE_MAKEFILE ON)

And this is the build output (updated):

/home/leo/clion-2017.2.3/bin/cmake/bin/cmake --build /home/leo/CLionProjects/C++Threads/cmake-build-debug --target C__Threads -- -j 4
/home/leo/clion-2017.2.3/bin/cmake/bin/cmake -H/home/leo/CLionProjects/C++Threads -B/home/leo/CLionProjects/C++Threads/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/make -f CMakeFiles/Makefile2 C__Threads
make[1]: Entering directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
/home/leo/clion-2017.2.3/bin/cmake/bin/cmake -H/home/leo/CLionProjects/C++Threads -B/home/leo/CLionProjects/C++Threads/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/home/leo/clion-2017.2.3/bin/cmake/bin/cmake -E cmake_progress_start /home/leo/CLionProjects/C++Threads/cmake-build-debug/CMakeFiles 2
/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/C__Threads.dir/all
make[2]: Entering directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
/usr/bin/make -f CMakeFiles/C__Threads.dir/build.make CMakeFiles/C__Threads.dir/depend
make[3]: Entering directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
cd /home/leo/CLionProjects/C++Threads/cmake-build-debug && /home/leo/clion-2017.2.3/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /home/leo/CLionProjects/C++Threads /home/leo/CLionProjects/C++Threads /home/leo/CLionProjects/C++Threads/cmake-build-debug /home/leo/CLionProjects/C++Threads/cmake-build-debug /home/leo/CLionProjects/C++Threads/cmake-build-debug/CMakeFiles/C__Threads.dir/DependInfo.cmake --color=
make[3]: Leaving directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
/usr/bin/make -f CMakeFiles/C__Threads.dir/build.make CMakeFiles/C__Threads.dir/build
make[3]: Entering directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
[ 50%] Building CXX object CMakeFiles/C__Threads.dir/main.cpp.o
/usr/bin/c++    -fcilkplus -g   -fcilkplus -std=gnu++11 -o CMakeFiles/C__Threads.dir/main.cpp.o -c /home/leo/CLionProjects/C++Threads/main.cpp
[100%] Linking CXX executable C__Threads
/home/leo/clion-2017.2.3/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/C__Threads.dir/link.txt --verbose=1
/usr/bin/c++  -fcilkplus -g   CMakeFiles/C__Threads.dir/main.cpp.o  -o C__Threads 
make[3]: Leaving directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
[100%] Built target C__Threads
make[2]: Leaving directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
/home/leo/clion-2017.2.3/bin/cmake/bin/cmake -E cmake_progress_start /home/leo/CLionProjects/C++Threads/cmake-build-debug/CMakeFiles 0
make[1]: Leaving directory '/home/leo/CLionProjects/C++Threads/cmake-build-debug'
leqo
  • 356
  • 4
  • 15
  • Clion uses [CMake](https://cmake.org/) for its projects. I suggest you read its [documentation](https://cmake.org/cmake/help/latest/index.html). – Some programmer dude Oct 06 '17 at 19:08
  • The problem is not CMake. I think I managed to pass the -fcilkplus option, but the IDE won't compile (there's still the red squiggly line under the cilk_spawn keyword). – leqo Oct 08 '17 at 19:48
  • If you [read the `cilk-plus` tag info](https://stackoverflow.com/tags/cilk-plus/info) it says "**Intel®** Cilk™ Plus is an extension to C and C++" (emphasis mine). Intel language extensions like that are usually only in the Intel compilers, are you sure GCC support it? – Some programmer dude Oct 09 '17 at 04:31
  • Well yes, because if I type in terminal "g++ - fcilkplus" specifying the .cpp file, everything works fine. – leqo Oct 10 '17 at 08:43
  • Can you please show us you `CMakeLists.txt` file? How do you add the option? – Some programmer dude Oct 10 '17 at 08:51
  • Also, if you make a verbose build (you can do it by editing the `CMakeCache.txt` file, changing `CMAKE_VERBOSE_MAKEFILE`), clean and then rebuild, you will see all commands being executed when building, including flags. Do it look correct to you? Is the flag included? – Some programmer dude Oct 10 '17 at 09:32
  • Looks like the option is not in the build output. – leqo Oct 11 '17 at 18:05

1 Answers1

1

You need to set CMAKE_CXX_FLAGS before you create the target with add_executable.

However, I suggest you use target_compile_option instead:

target_compile_options(C__Threads PUBLIC -fcilkplus)

Of course, this has to be done after the add_executable.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • I added what you were suggesting. The build succeeds, but the program won't run (those red squiggly lines under cilk_spawn are still there). By the way, I updated the content of CMakeLists.txt and the build output. – leqo Oct 12 '17 at 21:03
  • @leqo That "won't run" and the red squiggly lines are two different problems, unrelated to the build problem. The squiggly lines is probably because Cilk is an *extension* to the language, one that CLion doesn't recognize yet. The "won't run" problem is unfortunately not something I can help with, and is the subject for another question. – Some programmer dude Oct 13 '17 at 05:40
  • @leqo Oh and please don't update the code in the question to include solutions from answers, as suddenly the question doesn't have the problem asked about any more, and it makes the answers worthless. Instead just either mark an answer as accepted (click the "tick" next to the answer) to say that it was the answer that solved *this* problem. Or if an answer was helpful add a comment that it helped but didn't solve the problem completely, and possibly vote it up. You can then edit your question to *add* that "this answer helped but I still have these problems". – Some programmer dude Oct 13 '17 at 05:45
  • Well thanks for your answer, but the problem remains unsolved – leqo Oct 15 '17 at 22:20