c – 如何告诉CMake在Windows上使用Clang?
我有一个使用CMake构建的C项目.我通常在OSX上构建,但现在我正在尝试使用
Windows版本.出于兼容性原因,我想在Windows上使用Clang.
我从LLVM安装了预编译的Clang 3.8二进制文件: C:Program FilesLLVMbinclang.exe C:Program FilesLLVMbinclang++.exe 它也安装在我的PATH上: >clang++ clang++.exe: error: no input files 我有两个问题: >当我打电话给cmake –build时,如何告诉CMake使用clang? 解决方法
除了Clang编译器本身之外,您还需要一个适用于Windows的构建/链接环境.
最新的CMake 3.6版本在Windows上有几个集成支持的Clang构建环境(例如Visual Studio,Cygwin;见Release Notes). 我刚刚用一个成功的测试 > LLVM-3.9.0-r273898-win32.exe从http://llvm.org/builds/ 全部安装到其标准路径,其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> DebugHelloWorld.exe Hello World! 安装提示 请注意,我在设置过程中已将LLVM添加到搜索路径中: 您可以在任何VS项目的属性页面中交叉检查可用的“平台工具集”: 参考 > What is the -D define to tell Cmake where to find nmake? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |