Try using Homebrew's llvm:brew install llvm然后,您将所有llvm二进制文件保存在/usr/local/opt/llvm/bin 中.例如,要编译 OpenMP Hello World程序,请键入You then have all the llvm binaries in /usr/local/opt/llvm/bin. To compile the OpenMP Hello World program, for example, type/usr/local/opt/llvm/bin/clang -fopenmp -L/usr/local/opt/llvm/lib omp_hello.c -o hello您可能还必须使用 -I/usr/local/opt/llvm/include 设置 CPPFLAGS .You might also have to set the CPPFLAGS with -I/usr/local/opt/llvm/include. makefile应该如下所示:A makefile should look like this:CPP = /usr/local/opt/llvm/bin/clangCPPFLAGS = -I/usr/local/opt/llvm/include -fopenmpLDFLAGS = -L/usr/local/opt/llvm/libomp_hello: omp_hello.c $(CPP) $(CPPFLAGS) $^ -o $@ $(LDFLAGS) 更新:在macOS 10.14(Mojave)中,您可能会收到类似错误Update: In macOS 10.14 (Mojave) you might get an error like/usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1/include/omp.h:118:13: fatal error: 'stdlib.h' file not found如果发生这种情况,则/usr/include 中缺少macOS SDK标头.他们使用 Xcode 10 进入了SDK本身.使用If this happens, the macOS SDK headers are missing from /usr/include. They moved into the SDK itself with Xcode 10. Install the headers into /usr/include withopen /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 更新2:样本文件 omp_hello.c 似乎已从上面的直接链接中删除,所以它是:Update 2: The sample file omp_hello.c seems to be gone from the direct link above, so here it is:/******************************************************************************* FILE: omp_hello.c* DESCRIPTION:* OpenMP Example - Hello World - C/C++ Version* In this simple example, the master thread forks a parallel region.* All threads in the team obtain their unique thread number and print it.* The master thread only prints the total number of threads. Two OpenMP* library routines are used to obtain the number of threads and each* thread's number.* AUTHOR: Blaise Barney 5/99* LAST REVISED: 04/06/05******************************************************************************/#include <omp.h>#include <stdio.h>#include <stdlib.h>int main (int argc, char *argv[]){int nthreads, tid;/* Fork a team of threads giving them their own copies of variables */#pragma omp parallel private(nthreads, tid) { /* Obtain thread number */ tid = omp_get_thread_num(); printf("Hello World from thread = %d\n", tid); /* Only master thread does this */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } /* All threads join master thread and disband */} 这篇关于在Mac OS X(Sierra& amp; Mojave)的clang中启用OpenMP支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 05:10