Windows中的OpenMP代码的LLVM/Clang 8编译 [英] LLVM / Clang 8 Compilation of OpenMP Code in Windows

查看:363
本文介绍了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:

  1. libomp.lib.
  2. libiomp5md.dll.
  1. libomp.lib.
  2. libiomp5md.dll.

我的问题是:

  1. 编译代码时,我将标志-Xclang -fopenmp用于编译器.在GCC和ICC中,使用标志告诉编译器自动链接OpenMP库.那C呢它是自动执行的还是必须手动与libomp.lib链接?有没有办法触发自动链接到OpenMP库?
    答案:在 Michael Klemm
  1. 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 with libomp.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 the clang driver both for compiling and linking and then the -fopenmp will work as in GCC.
  2. When I link with 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. Is that a bug or is it because I link manually?
    Answer: The libomp.dll is supplied in the bin folder and not the lib folder.
  3. 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's cl compiler.
    Answer: Currently it can be done either with clang -fopenmp ..., clang-cl -Xclang -fopenmp ... or clang-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编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆