本文介绍了Windows中的OpenMP代码的LLVM/Clang 8编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Windows下使用Windows版本的 Clang (LLVM)8. br>我正在编译使用 OpenMP 的代码.
I'm using the Windows version of Clang (LLVM) 8 under Windows.
I'm compiling a code which uses OpenMP.
在Clang的lib
文件夹下,有2个与OpenMP相关的文件:
Under the lib
folder of Clang there are 2 files which are OpenMP related:
-
libomp.lib
. -
libiomp5md.dll
.
libomp.lib
.libiomp5md.dll
.
我的问题是:
- 编译代码时,我将标志
-Xclang -fopenmp
用于编译器.在GCC和ICC中,使用标志告诉编译器自动链接OpenMP库.那C呢它是自动执行的还是必须手动与libomp.lib
链接?有没有办法触发自动链接到OpenMP库?
答案:在 Michael Klemm 的-使用clang
驱动程序进行编译和链接,然后-fopenmp
将像GCC
一样工作. - 当我手动链接
libomp.lib
(定义为链接程序的库)时,输出exe
需要libomp.dll
,而提供的OpenMP动态库是libiomp5md.dll
.那是错误还是因为我手动链接?
答案:libomp.dll
在bin
文件夹中提供,而不在lib
文件夹中. - 在Windows下的Clang中使用OpenMP的正确方法是什么?
clang-cl
驱动程序不适用于/openmp
或-openmp
作为MSVC的cl
编译器.
答案:目前可以使用clang -fopenmp ...
,clang-cl -Xclang -fopenmp ...
或clang-cl /clang:-fopenmp ...
(相当于-Xclang -fopenmp
)完成.
- When I compile the code I use the flags
-Xclang -fopenmp
for 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.lib
manually? Is there a way to trigger automatic linking to the OpenMP library?
Answer: This was answered in Michael Klemm's answer below - Use theclang
driver both for compiling and linking and then the-fopenmp
will work as inGCC
. - When I link with
libomp.lib
manually (Defining as a library for the linker) the outputexe
requireslibomp.dll
while the supplied OpenMP Dynamic Library islibiomp5md.dll
. Is that a bug or is it because I link manually?
Answer: Thelibomp.dll
is supplied in thebin
folder and not thelib
folder. - What's the proper way to utilize OpenMP in Clang under Windows? The
clang-cl
driver doesn't work with/openmp
or-openmp
as the MSVC'scl
compiler.
Answer: Currently it can be done either withclang -fopenmp ...
,clang-cl -Xclang -fopenmp ...
orclang-cl /clang:-fopenmp ...
(Which is equivalent of-Xclang -fopenmp
).
备注
在Windows上,我使用clang-cl
使用Clang的Windows驱动程序.
Remark
On Windows I use Windows Driver of Clang using clang-cl
.
推荐答案
要在Windows上使用clang编译和链接OpenMP代码,则必须将-fopenmp
传递给编译器和链接器:
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
这篇关于Windows中的OpenMP代码的LLVM/Clang 8编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!