在Windows中配置CMake以使用命令行中的clang获得最新的OpenMP支持 [英] Configure CMake in windows to use clang from command line to get modern OpenMP support

查看:418
本文介绍了在Windows中配置CMake以使用命令行中的clang获得最新的OpenMP支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型测试项目,该测试使用OpenMP进行并行化.我的目标是对其进行编译,以便为库生成.dll.lib(因为我的真实项目链接到使用这些类型分发的外部库),并且支持OpenMP 4.5或更高版本,并且可以从命令行进行操作,因此可以在docker上进行测试和检查(docker部分不在此问题的范围内,仅供参考,以说明我为什么需要从命令行运行它).我可以使用不满意的其他编译器来编译该项目:

I have a small test project that uses OpenMP for parallelization. My target is to compile it so it produces .dll and .lib for libraries (because my real project links to external libraries distributed using these types), with support for OpenMP 4.5 or newer and do it from the command line so it can be done on a docker for testing and checking (the docker part is out of the scope of this question, it is just for reference on why I need it to work from the command line). I can compile this project with different compilers with which I am not happy:

  • MSVC:mkdir build-msvc,然后是cmake ..(来自新创建的文件夹),最后是cmake --build . --config Release.可以很好地编译,但是仅支持OpenMP 2.0,因此对于我的真实项目不是一个好的选择.
  • Intel Parallel Studio:mkdir build-intel,然后是cmake .. -T "Intel C++ Compiler 19.0"(来自新创建的文件夹),最后是cmake --build . --config Release.它支持OpenMP 5.0,但其许可证对我而言却非常昂贵.
  • MinGW x64 g ++:mkdir build-g++,然后是cmake .. -G "MinGW Makefiles"(来自新创建的文件夹),最后是cmake --build ..它支持OpenMP 4.5,但此编译器与.lib(据我所知)不兼容,而我已经提到.lib对我来说是必需的.
  • MSVC: mkdir build-msvc, then cmake .. (from the newly created folder) and finally cmake --build . --config Release. This compiles fine but only supports OpenMP 2.0, therefore is not a good option for my real project.
  • Intel Parallel Studio: mkdir build-intel, then cmake .. -T "Intel C++ Compiler 19.0" (from the newly created folder) and finally cmake --build . --config Release. This supports OpenMP 5.0 but its licenses are pretty expensive for me.
  • MinGW x64 g++: mkdir build-g++, then cmake .. -G "MinGW Makefiles" (from the newly created folder) and finally cmake --build .. It supports OpenMP 4.5 but this compiler is not compatible wiht .lib (as far as I know) which I already mentioned is necessary for me.

我尝试使用clang失败,

I have tried without success to use clang:

    从MSVC中
  • CLANG:mkdir build-clang-msvc,然后是cmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl ..(来自新创建的文件夹),但是失败并显示以下错误:
  • CLANG from MSVC: mkdir build-clang-msvc, then cmake -G Ninja -DCMAKE_CXX_COMPILER=clang-cl .. (from the newly created folder), but it fails with the following error:

-- The CXX compiler identification is Clang 8.0.1 with MSVC-like command-line
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/[USER NAME]/source/repos/test_openmp/build-clang-msvc/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/PROGRA~2/MICROS~1/2019/COMMUN~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe cmTC_bd131 && [1/2] Building CXX object CMakeFiles\cmTC_bd131.dir\testCXXCompiler.cxx.obj
    [2/2] Linking CXX executable cmTC_bd131.exe
    FAILED: cmTC_bd131.exe
    cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_bd131.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests  -- C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\ld.exe /nologo CMakeFiles\cmTC_bd131.dir\testCXXCompiler.cxx.obj  /out:cmTC_bd131.exe /implib:cmTC_bd131.lib /pdb:cmTC_bd131.pdb /version:0.0  /machine:X86  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_bd131.dir/manifest.res CMakeFiles\cmTC_bd131.dir/manifest.rc" failed (exit code 0) with the following output:
    The system cannot find the file specified
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/[USER NAME]/source/repos/test_openmp/build-clang-msvc/CMakeFiles/CMakeOutput.log".
See also "C:/Users/[USER NAME]/source/repos/test_openmp/build-clang-msvc/CMakeFiles/CMakeError.log".

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