有人知道如何在 gcc5.2.0 中使用 Cilk plus 正确编译以下代码吗?使用 gcc -fcilkplus * 或 g++,我总是会出错。
#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;
}
结果:
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
网上关于这个的话题很少。谢谢