[英]LLVM / Clang 8 Compilation of OpenMP Code in Windows
I'm using the Windows version of Clang (LLVM) 8 under Windows.我在 Windows 下使用Clang (LLVM) 8 的 Windows 版本。
I'm compiling a code which uses OpenMP .我正在编译使用OpenMP的代码。
Under the lib
folder of Clang there are 2 files which are OpenMP related:在 Clang 的
lib
文件夹下有 2 个与 OpenMP 相关的文件:
libomp.lib
. libomp.lib
。libiomp5md.dll
. libiomp5md.dll
。 My questions are:我的问题是:
-Xclang -fopenmp
for the compiler.-Xclang -fopenmp
。 In in GCC and ICC using the flags tell the compiler to link the OpenMP library automatically.libomp.lib
manually?libomp.lib
? Is there a way to trigger automatic linking to the OpenMP library?clang
driver both for compiling and linking and then the -fopenmp
will work as in GCC
.clang
驱动程序进行编译和链接,然后-fopenmp
将像在GCC
中一样工作。libomp.lib
manually (Defining as a library for the linker) the output exe
requires libomp.dll
while the supplied OpenMP Dynamic Library is libiomp5md.dll
.libomp.lib
(定义为链接器的库)时,output exe
需要libomp.dll
,而提供的 OpenMP 动态库是libiomp5md.dll
。 Is that a bug or is it because I link manually?libomp.dll
is supplied in the bin
folder and not the lib
folder.libomp.dll
在bin
文件夹中提供,而不是在lib
文件夹中提供。clang-cl
driver doesn't work with /openmp
or -openmp
as the MSVC's cl
compiler. clang-cl
驱动程序不适用于/openmp
或-openmp
作为 MSVC 的cl
编译器。clang -fopenmp...
, clang-cl -Xclang -fopenmp...
or clang-cl /clang:-fopenmp...
(Which is equivalent of -Xclang -fopenmp
).clang -fopenmp...
、 clang-cl -Xclang -fopenmp...
或clang-cl /clang:-fopenmp...
(相当于-Xclang -fopenmp
)来完成。 Remark评论
On Windows I use Windows Driver of Clang using clang-cl
.在 Windows 上,我使用 Windows Driver of Clang using
clang-cl
。
Adding clarity to what the OpenMP libraries actually are, and how to use them on Windows with clang-cl
进一步说明 OpenMP 库的实际含义,以及如何使用
clang-cl
在 Windows 上使用它们
libomp.dll and libiomp5md.dll ARE THE SAME FILES! libomp.dll 和 libiomp5md.dll 是相同的文件!
When compiling for Windows, you link against libomp.lib
OR libiomp5md.lib
which will link to the same-named DLL at runtime, ie libomp.dll
OR libiomp5md.dll
respectively.为 Windows 编译时,您链接到
libomp.lib
或libiomp5md.lib
,它们将在运行时链接到同名的 DLL,即分别libomp.dll
或libiomp5md.dll
。
If you load 2 files that use the "different-name DLL," the interpreter will crash and give you a nasty error like: OMP: Error #15: Initializing libiomp5md.dll, but found libomp.dll already initialized.如果您加载 2 个使用“不同名称 DLL”的文件,解释器将崩溃并给您一个令人讨厌的错误,例如: OMP:错误 #15:初始化 libiomp5md.dll,但发现 libomp.dll 已经初始化。
Why?为什么? Because the program has no idea they are the same DLL, they have different names, so it assumes they are different.
因为程序不知道它们是相同的 DLL,它们具有不同的名称,所以它假定它们是不同的。 And it crashes.
它崩溃了。 For this reason only, you can choose to swap which OpenMP DLL you link to in your program.
仅出于这个原因,您可以选择交换您在程序中链接到的 OpenMP DLL。
If your program doesn't crash and give you an error, you can keep using the same link to OpenMP.如果您的程序没有崩溃并给您一个错误,您可以继续使用相同的 OpenMP 链接。 Otherwise, to silence the error, link to the one that is loaded by another program already.
否则,要消除错误,请链接到已经由另一个程序加载的错误。
If using clang-cl.exe
which is the "drop-in" Clang replacement for MSVC cl.exe
you should pass a compiler argument such as -Xclang -fopenmp
which will convert the argument over to "Clang language."如果使用
clang-cl.exe
,它是 MSVC cl.exe
的“插入式”Clang 替代品,您应该传递一个编译器参数,例如-Xclang -fopenmp
,它将把参数转换为“Clang 语言”。 Don't forget to still pass to the linker the OpenMP LIB you chose, because on Windows, it won't be automatic.不要忘记仍然将您选择的 OpenMP LIB 传递给 linker,因为在 Windows 上,它不会是自动的。
That's all I've learned as brief as possible about OpenMP linking on Windows.这就是我在 Windows 上尽可能简要地了解 OpenMP 链接的全部内容。
To compile and link OpenMP code with clang on Windows, you will have to pass -fopenmp
to both the compiler and the linker:要在 Windows 上使用 clang 编译和链接 OpenMP 代码,您必须将
-fopenmp
传递给编译器和链接器:
clang -fopenmp -o bla.obj -c bla.c
clang -fopenmp -o bla.exe bla.obj
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.