【发布时间】:2022-09-24 22:30:49
【问题描述】:
我试图确定 CMake 是否是简化我正在研究的 c++ 库的跨平台开发的一个选项。 Linux 完成了。现在,我正在尝试在 Windows 上使用 CMake。使用 CMake 的 Visual Studio 生成器设置 CMake 也不是问题。我还在一个简单的程序“hello_world.cpp”上对其进行了测试。
mkdir build
cd build
cmake ..
msbuild hello_world.sln
当我尝试使用英特尔编译器为 Microsoft Visual Studio 配置 CMake 时,就会出现问题,正如Intel 所解释的那样。 按照Intel 的简单程序“hello_world.cpp”,我在power-shell 中执行了以下操作
mkdir build
cd build
cmd.exe \"/K\" \'\"C:\\Program Files (x86)\\Intel\\oneAPI\\setvars.bat\" && powershell\'
cmake -T \"Intel(R) oneAPI DPC++ Compiler\" -DCMAKE_CXX_COMPILER=\"dpcpp\" ..
输出是
:: initializing oneAPI environment...
Initializing Visual Studio command-line environment...
Visual Studio version 16.11.19 environment configured.
\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\\"
Visual Studio command-line environment initialized for: \'x64\'
: advisor -- latest
: compiler -- latest
: dal -- latest
: debugger -- latest
: dev-utilities -- latest
: dnnl -- latest
: dpcpp-ct -- latest
: dpl -- latest
: inspector -- latest
: intelpython -- latest
: ipp -- latest
: ippcp -- latest
: itac -- latest
: mkl -- latest
: mpi -- latest
: tbb -- latest
: vpl -- latest
: vtune -- latest
:: oneAPI environment initialized ::
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
-- Building for: Visual Studio 16 2019
CMake Error at CMakeLists.txt:1 (project):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 21/09/2022 15:52:09.
Project \"C:\\Users\\RaphaelSchiedung\\source\\hello_world\\build\\CMakeFiles\\3.24.2\\VCTargetsPath.vcxproj\" on node 1 (default targets).
C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\MSBuild\\Microsoft\\VC\\v160\\Microsoft.CppBuild.targets(439,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\\RaphaelSchiedung\\source\\hello_world\\build\\CMakeFiles\\3.24.2\\VCTargetsPath.vcxproj]
Done Building Project \"C:\\Users\\RaphaelSchiedung\\source\\hello_world\\build\\CMakeFiles\\3.24.2\\VCTargetsPath.vcxproj\" (default targets) -- FAILED.
Build FAILED.
\"C:\\Users\\RaphaelSchiedung\\source\\hello_world\\build\\CMakeFiles\\3.24.2\\VCTargetsPath.vcxproj\" (default target) (1) ->
(PrepareForBuild target) ->
C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\MSBuild\\Microsoft\\VC\\v160\\Microsoft.CppBuild.targets(439,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\\RaphaelSchiedung\\source\\hello_world\\build\\CMakeFiles\\3.24.2\\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.21
Exit code: 1
-- Configuring incomplete, errors occurred!
问题似乎是 VCTargetsPath。 Microsoft 称其为引用 %VSINSTALLDIR%MSBuild\\Microsoft\\VC<version>\\ 的宏。在这一点上,谷歌在回答我关于检查 VCTargetPah 是否设置正确的问题方面没有多大帮助。它在哪里定义?注册表、系统变量,还是在 VisualStudio 的某些项目文件中?我不太了解这一点,我对 Windows 编程也不太了解。
它是一个错误吗? VCTargetsPath 是问题所在吗?我能做点什么吗?任何有关如何进行的帮助将不胜感激。
hello_world.cpp:
#include<iostream>
int main(){std::cout << \"Hello World\\n\"; return 0;}
CMakeLists.txt:
project(hello_world)
add_executable(hello_world hello_world.cpp)
窗口 11
视觉工作室 16 2019
CMake 版本 3.24.2
Intel(R) oneAPI DPC++/C++ 编译器 2022.1.0 (2022.1.0.20220316)
-
这看起来完全倒退了。您调用 cmake 来创建构建目录并为您生成解决方案,而不是相反。
-
好吧,这就是我所理解的目的 CMake。它根据操作系统生成 Makefile 或解决方案。如果我想自己创建 Makefile 或解决方案,就像我目前所做的那样,我应该出于什么目的使用 CMake?
标签: c++ visual-studio cmake intel-oneapi