c – 如何告诉CMake在Windows上使用Clang?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c – 如何告诉CMake在Windows上使用Clang?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2407字,纯文字阅读大概需要4分钟。
内容图文
我有一个使用CMake构建的C项目.我通常在OSX上构建,但现在我正在尝试使用Windows版本.出于兼容性原因,我想在Windows上使用Clang.
我从LLVM安装了预编译的Clang 3.8二进制文件:
C:\Program Files\LLVM\bin\clang.exe
C:\Program Files\LLVM\bin\clang++.exe
它也安装在我的PATH上:
>clang++
clang++.exe: error: no input files
我有两个问题:
>当我打电话给cmake –build时,如何告诉CMake使用clang?
>如何在构建CMake配置的编译器之前检查?
解决方法:
除了Clang编译器本身之外,您还需要一个适用于Windows的构建/链接环境.
最新的CMake 3.6版本在Windows上有几个集成支持的Clang构建环境(例如Visual Studio,Cygwin;见Release Notes).
我刚刚用一个成功的测试
> LLVM-3.9.0-r273898-win32.exe从http://llvm.org/builds/
> cmake-3.6.0-rc4-win64-x64.msi从https://cmake.org/download/
> Microsoft VS2015 Community Edition版本14.0.23107.0
全部安装到其标准路径,其bin目录位于全局PATH环境中.
您需要知道的部分是使用CMake -T“LLVM-vs2014”命令行选项设置正确的工具集.在配置过程中,CMake会告诉您它找到/采用的编译器.
的CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(HelloWorld)
file(
WRITE main.cpp
"#include <iostream>\n"
"int main() { std::cout << \"Hello World!\" << std::endl; return 0; }"
)
add_executable(${PROJECT_NAME} main.cpp)
Windows控制台
...> mkdir VS2015
...> cd VS2015
...\VS2015> cmake -G"Visual Studio 14 2015" -T"LLVM-vs2014" ..
-- The C compiler identification is Clang 3.9.0
-- The CXX compiler identification is Clang 3.9.0
-- Check for working C compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: .../VS2015
...\VS2015> cmake --build .
Microsoft (R)-Buildmodul, Version 14.0.23107.0
[...]
...\VS2015> Debug\HelloWorld.exe
Hello World!
安装提示
请注意,我在设置过程中已将LLVM添加到搜索路径中:
您可以在任何VS项目的属性页面中交叉检查可用的“平台工具集”:
参考
> What is the -D define to tell Cmake where to find nmake?
> Linker for Clang?
> Switching between GCC and Clang/LLVM using CMake
内容总结
以上是互联网集市为您收集整理的c – 如何告诉CMake在Windows上使用Clang?全部内容,希望文章能够帮你解决c – 如何告诉CMake在Windows上使用Clang?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。