【问题标题】:How to generate a Visual Studio project that uses the Intel Compiler using cmake under Windows如何在 Windows 下使用 cmake 生成使用英特尔编译器的 Visual Studio 项目
【发布时间】:2015-02-21 18:11:09
【问题描述】:

我正在用 C 语言开发一个跨平台 (Linux/Windows) 应用程序。我已经厌倦了同时维护可用的 Makefile 和 Visual Studio 解决方案/项目,所以我想过渡到 cmake。我在两个平台上都使用英特尔编译器。

我已经下载了 Windows 上的 cmake 3.0 和 Linux 上的 cmake 2.8(它是 ubuntu 12.04 存储库中的那个)。在 Linux 上一切顺利,Makefile 生成成功。跑起来很简单:CC=icc CXX=icc cmake ..

然而,在 Windows 上,无论我尝试什么命令,我都无法使用英特尔编译器。输出 vcxproj 始终使用 MSVC 编译器。

我尝试了以下命令:

cmake -G "Visual Studio 11 2012 Win64" -D CMAKE_C_COMPILER="C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe" -D CMAKE_CXX_COMPILER="C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe" ..

输出是:

-- The C compiler identification is MSVC 17.0.61030.0
-- The CXX compiler identification is MSVC 17.0.61030.0
-- Check for working C compiler using: Visual Studio 11 2012 Win64
-- Check for working C compiler using: Visual Studio 11 2012 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11 2012 Win64
-- Check for working CXX compiler using: Visual Studio 11 2012 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done

当我将生成器更改为“NMake Makefiles”时,icc 被设置为编译器。

-- The C compiler identification is Intel 14.0.3.20140422
-- The CXX compiler identification is Intel 14.0.3.20140422
-- Check for working C compiler: C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe

我在一个只有一个源文件的非常基本的项目上进行测试,所以我的 CMakeLists.txt 文件只包含:

project(dummy_cmake)

add_executable(hellonikola main.c)

非常感谢任何帮助!

附言

cmake-gui 的行为相同。我选择指定一个不同的原生编译器,并给出 icc 的路径并获得上述输出。

我也试过在 Windows 上使用 cmake 2.8 并且行为是一样的。

【问题讨论】:

  • 在将生成器用作“NMake Makefiles”时,我遇到了与您相同的问题。不过,您的解决方案在我的情况下不起作用。

标签: visual-studio visual-studio-2012 cmake icc


【解决方案1】:

我找到了答案,所以我发布它以防其他人有同样的问题。

解决方案是将此行添加到CMakeLists.txt

set(CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler XE 14.0" CACHE STRING "Platform Toolset" FORCE)

我发现了这个on this blog 并对其进行了调整以使用英特尔编译器。

【讨论】:

  • 可以在命令行中使用相同的字符串:cmake -T"Intel C++ Compiler XE 14.0" ...
  • 注: docs 明确地说“这个变量的值永远不应该被项目代码修改。”
  • 对于当前版本的工具集名称是“Intel C++ Compiler 16.0”
猜你喜欢
  • 1970-01-01
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多