Does anybody know how to compile the following code with Cilk plus in gcc5.2.0 correctly? With gcc -fcilkplus * or g++, I always get errors.
#include <cilk/cilk.h>
#include <assert.h>
int fib(int n) {
if (n < 2)
return n;
int a = cilk_spawn fib(n-1);
int b = fib(n-2);
cilk_sync;
return a + b;
}
int main() {
int result = fib(30);
assert(result == 832040);
return 0;
}
result:
Undefined symbols for architecture x86_64:
"___cilkrts_enter_frame_1", referenced from:
fib(int) in ccY1qrGL.o
"___cilkrts_enter_frame_fast_1", referenced from:
__cilk_spn_0 in ccY1qrGL.o
"___cilkrts_leave_frame", referenced from:
fib(int) in ccY1qrGL.o
__cilk_spn_0 in ccY1qrGL.o
"___cilkrts_rethrow", referenced from:
fib(int) in ccY1qrGL.o
"___cilkrts_save_fp_ctrl_state", referenced from:
fib(int) in ccY1qrGL.o
"___cilkrts_sync", referenced from:
fib(int) in ccY1qrGL.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
There are very few topics about this online. thanks