目前,我在SNow Leopard的XCode 3.2.2上尝试OpenMP:
#include <omp.h> #include <iostream> #include <stdio.h> int main (int argc,char * const argv[]) { #pragma omp parallel printf("Hello from thread %d,nthreads %d\n",omp_get_thread_num(),omp_get_num_threads()); return 0; }
我还没有包含任何链接库,所以链接器抱怨:
“_omp_get_thread_num”,referenced from: _main in main.o
“_omp_get_num_threads”,referenced from: _main in main.o
好的,没问题,我看看现有的框架,寻找关键字,如openmp或omp ……这里出现问题,链接库在哪里?或者我应该说,openMP的链接库的名称是什么?它是dylib,框架还是什么?或者我是否需要先从某个地方获取它?
解决方法
如果有人想知道如何在XCode 4中编译它,我也必须启用OpenMP支持.
我通过单击项目启用了OpenMP支持,然后在“构建选项”下,我将“启用OpenMP支持”从“否”更改为“是”.
此外,我不得不将编译器版本从“LLVM 2.0”更改为“GCC 4.2”或“LLVM GCC 4.2”.否则,编译器找不到“omp.h”.