[英]Configuring CMake and Microsoft Visual Studio 2019 for Use with Intel Compilers
I tried to determine if CMake is an option to simplify the cross-platform development of a c++ library that I am working on.我试图确定 CMake 是否是简化我正在研究的 c++ 库的跨平台开发的一个选项。 Linux is done.
Linux 完成。 Now, I am trying to use CMake on windows.
现在,我正在尝试在 windows 上使用 CMake。 Setting up CMake using the Visual Studio Generators of CMake was also not an issue.
使用 CMake 的 Visual Studio 生成器设置 CMake 也不是问题。 I tested it also on a simple program "hello_world.cpp".
我还在一个简单的程序“hello_world.cpp”上对其进行了测试。
mkdir build
cd build
cmake ..
msbuild hello_world.sln
The problem arises when I try to configure CMake for Microsoft Visual Studio with Intel Compilers as explained by Intel .当我尝试使用 Intel 编译器为 Microsoft Visual Studio 配置 CMake 时出现问题,正如Intel所解释的那样。 Following Intel for the simple program "hello_world.cpp", I did the following in the power-shell
按照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" ..
the output was output 是
:: 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!
The problem seems to be VCTargetsPath.问题似乎是 VCTargetsPath。 Microsoft calls it a macro referencing %VSINSTALLDIR%MSBuild\Microsoft\VC<version>\.
Microsoft将其称为引用 %VSINSTALLDIR%MSBuild\Microsoft\VC<version>\ 的宏。 At this point, google did not help much in answering my question on checking if VCTargetPah is set correctly.
在这一点上,谷歌在回答我关于检查 VCTargetPah 是否设置正确的问题方面没有多大帮助。 Where is it defined?
它在哪里定义? Registry, System variable, or in some project files of VisualStudio?
注册表、系统变量,还是在 VisualStudio 的某些项目文件中? I did not quite understand this and I do not know much about windows programming.
我不太了解这一点,我对 windows 编程了解不多。
Is it a bug?它是一个错误吗? Is VCTagetsPath the problem at all?
VCTagetsPath 是问题所在吗? Can I do something about it?
我能做点什么吗? Any help on how to proceed would be appreciated.
任何有关如何进行的帮助将不胜感激。
hello_world.cpp: hello_world.cpp:
#include<iostream>
int main(){std::cout << "Hello World\n"; return 0;}
CMakeLists.txt: CMakeLists.txt:
project(hello_world)
add_executable(hello_world hello_world.cpp)
window 11 window 11
Visual Studio 16 2019视觉工作室 16 2019
CMake version 3.24.2 CMake 版本 3.24.2
Intel(R) oneAPI DPC++/C++ Compiler 2022.1.0 (2022.1.0.20220316) Intel(R) oneAPI DPC++/C++ 编译器 2022.1.0 (2022.1.0.20220316)
Can you try this:你可以试试这个:
cmake -DCMAKE_CXX_COMPILER=icx ..
instead of this:而不是这个:
cmake -T "Intel(R) oneAPI DPC++ Compiler" -DCMAKE_CXX_COMPILER="dpcpp" ..
FYI I think you were looking at old documentation, this was the latest for 2022.1 I think.仅供参考,我认为您正在查看旧文档,我认为这是 2022.1 的最新文档。
https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-setup/use-the-command-line/use-cmake-with-the-intel-oneapi-dpc-c-compiler.html https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-setup/use-the-command-行/使用-cmake-with-the-intel-oneapi-dpc-c-compiler.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.