在GCC5.2.0中编译Cilk plus

时间:2015-12-07 20:34:14

标签: c gcc cilk

有没有人知道如何在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

关于此在线的话题很少。感谢

1 个答案:

答案 0 :(得分:1)

GCC配置为在用户给出-fcilkplus时默认将-lcilkrts添加到其链接器命令,但如果存在任何特定于平台的配置,则可以覆盖此默认行为。我认为这是在OS X上发生的,但我认为需要修复它。无论如何,除了如上所述添加-lcilkrts之外,似乎没有短期解决方案。