问题
I'm using the Windows version of Clang (LLVM) 8 under Windows.
I'm compiling a code which uses OpenMP.
Under the lib folder of Clang there are 2 files which are OpenMP related:
libomp.lib.libiomp5md.dll.
My questions are:
- When I compile the code I use the flags
-Xclang -fopenmpfor the compiler. In in GCC and ICC using the flags tell the compiler to link the OpenMP library automatically. What about Clang? Does it do it automatically or must I link withlibomp.libmanually? Is there a way to trigger automatic linking to the OpenMP library?
Answer: This was answered in Michael Klemm's answer below - Use theclangdriver both for compiling and linking and then the-fopenmpwill work as inGCC. - When I link with
libomp.libmanually (Defining as a library for the linker) the outputexerequireslibomp.dllwhile the supplied OpenMP Dynamic Library islibiomp5md.dll. Is that a bug or is it because I link manually?
Answer: Thelibomp.dllis supplied in thebinfolder and not thelibfolder. - What's the proper way to utilize OpenMP in Clang under Windows? The
clang-cldriver doesn't work with/openmpor-openmpas the MSVC'sclcompiler.
Answer: Currently it can be done either withclang -fopenmp ...,clang-cl -Xclang -fopenmp ...orclang-cl /clang:-fopenmp ...(Which is equivalent of-Xclang -fopenmp).
Remark
On Windows I use Windows Driver of Clang using clang-cl.
回答1:
To compile and link OpenMP code with clang on Windows, you will have to pass -fopenmp to both the compiler and the linker:
clang -fopenmp -o bla.obj -c bla.c
clang -fopenmp -o bla.exe bla.obj
来源:https://stackoverflow.com/questions/55976484/llvm-clang-8-compilation-of-openmp-code-in-windows