有没有办法使用intel编译器运行cmake?

问题描述 投票:0回答:3

我尝试使用英特尔编译器运行程序,但在编译程序时显示错误。 这是由于 cmake 造成的。

cmake -G "Visual Studio 17 2022" -A x64 -T "Intel(R) oneAPI DPC++ Compiler" ..
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.25099.
CMake Error at CMakeLists.txt:81 (project):
Failed to run MSBuild command:
C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
to get the value of VCTargetsPath:
MSBuild version 17.3.1+2badb37d1 for .NET Framework
Build started 9/2/2022 10:51:43 AM.
Project "C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(460,5): error MSB8020: The build tools for Intel(R) oneAPI DPC++ Compiler (Platform Toolset = 'Intel(R) oneAPI DPC++ Compiler') cannot be found. 
To build using the Intel(R) oneAPI DPC++ Compiler build tools, please install Intel(R) oneAPI DPC++ Compiler build tools. 
Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj]
Done Building Project "C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj" (default targets) -- FAILED

"C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(460,5): error MSB8020: The build tools for Intel(R) oneAPI DPC++ Compiler (Platform Toolset = 'Intel(R) oneAPI DPC++ Compiler') cannot be found. To build using the Intel(R) oneAPI DPC++ Compiler build tools,
please install Intel(R) oneAPI DPC++ Compiler build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.15
Exit code: 1

cmake intel intel-oneapi
3个回答
1
投票

Ninja 是唯一适用于 Windows 且可与 oneAPI DPC++ 编译器配合使用的 CMake 生成器。

如果您希望使用英特尔 oneAPI DPC++ 编译器,请遵循以下链接中的说明: https://oneapi-src.github.io/oneDNN/dev_guide_build.html#id1

要使用英特尔下一代编译器,请使用以下命令:

cmake -G ""Visual Studio 17 2022"" -T ""Intel C++ Compiler 2022"" ...

0
投票

有几件事可能会导致您出现问题。

  1. 确保编译器已加载到您当前的命令环境中。对于英特尔编译器,这通常是
    C:\Program Files (x86)\Intel\oneAPI\setvars.bat
  2. 确保安装的 CMake 版本比您尝试使用的工具集新。具体来说,如果您使用的是 intel 2022,则CMake 版本 > 3.22.2。
  3. 你的CMakeLists.txt没有贴出来,但是根据Intel的文档,你需要添加
    find_package(IntelDPCPP REQUIRED)

此外,一旦您能够构建目标,我建议您改用

CMakePresets.json
文件来配置 CMake 构建。我有一个看起来像这样的:

在此预设文件中,缓存变量

INTEL_COMPILER
用于打开/关闭我的
CMakeLists.txt
中的特定英特尔编译器标志,例如
/fp:precise

CMakePresets.json

{
    "version": 3,
    "cmakeMinimumRequired": {
    "major": 3,
    "minor": 22,
    "patch": 2
    },
    "configurePresets": [
    {
        "name": "base",
        "hidden": true,
        "binaryDir": "${sourceDir}/_build/${presetName}"
    },
    {
        "name": "Windows",
        "hidden": true,
        "inherits": [
        "base"
        ],
        "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
        },
        "vendor": {
        "microsoft.com/VisualStudioSettings/CMake/1.0": {
            "hostOS": "Windows"
        }
        }
    },
    {
        "name": "Debug",
        "hidden": true,
        "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug"
        }
    },
    {
        "name": "Release",
        "hidden": true,
        "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release"
        }
    },
    {
        "name": "Intel - IDE",
        "hidden": true,
        "toolset": "Intel C++ Compiler 2022",
        "cacheVariables": {
        "INTEL_COMPILER": "ON"
        }
    },
    {
        "name": "Visual Studio 2022 - Intel",
        "displayName": "Visual Studio 2022 using Intel compiler",
        "inherits": [
        "Windows",
        "Intel - IDE"
        ],
        "generator": "Visual Studio 17 2022"
    }
    ],
    "buildPresets": [
    {
        "name": "Windows",
        "hidden": true,
        "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
        },
        "vendor": {
        "microsoft.com/VisualStudioSettings/CMake/1.0": {
            "hostOS": "Windows"
        }
        }
    },
    {
        "name": "Visual Studio 2022 - Intel",
        "displayName": "Visual Studio 2022 using Intel compiler",
        "inherits": [
        "Windows"
        ],
        "configurePreset": "Visual Studio 2022 - Intel"
    }
    ]
}

0
投票

我遇到了同样的问题,这里的答案至少为我指明了寻找指导的正确位置。从今天(2023 年 11 月)开始,IntelDPCPP 被视为已弃用,建议使用与行业标准兼容的 IntelSYCL。 所有信息都可以在这里找到:https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/use-cmake-with -the-compiler.html

© www.soinside.com 2019 - 2024. All rights reserved.