亲爱的C++编程员,
在使用Visual Studio工具链在Windows上构建一段时间后,我决定给Clang 5一个镜头.
我安装了LLVM 5.0.0二进制文件,Ninja构建环境,VS 2017工具和CMake 3.9.3.最终目标是能够使用VS Code编译C和C++应用程序,将CMake集成为"IDE",将Clang与LLD一起编译为编译器和链接器.
一个简单程序的编译和执行工作得非常好(相应终端历史的屏幕截图).Clang在VS Tools目录中自动检测到Windows的标准lib,并生成了可执行输出.
下一步是使用Ninja建立一个简单的构建(ninja.build文件和终端历史的截图).构建过程按预期工作,并像以前一样生成可运行的可执行文件.
当我开始将CMake集成到流程中时,问题就开始了.我的期望是CMake生成一个ninja构建文件并运行它,对吗?我尝试了以下CMakeLists文件
cmake_minimum_required(VERSION 3.9)
project(Test)
add_executable(Test main.c)
Run Code Online (Sandbox Code Playgroud)
并称为CMake cmake -G Ninja.由此产生的结果是令人失望的,我不明白,分别自己解决问题.
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: C:/Meine_Programme/LLVM/bin/clang.exe
-- Check for working C compiler: C:/Meine_Programme/LLVM/bin/clang.exe -- broken
CMake Error at C:/Meine_Programme/CMake/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Meine_Programme/LLVM/bin/clang.exe" is not able to
compile a simple test program.
It fails with …Run Code Online (Sandbox Code Playgroud) 我目前在Windows上安装了cmake,clang和ninja.我正在尝试使用CMake生成一个忍者构建文件来编译一个非常简单的hello world程序.
我的CMakeLists.txt看起来像这样:
cmake_minimum_required(VERSION 2.8)
project(test_project)
add_executable(main main.cpp)
Run Code Online (Sandbox Code Playgroud)
main.cpp 是一个简单的hello world程序.
在命令行上我运行这个:cmake -G Ninja ..我得到以下错误:
-- The C compiler identification is Clang 3.5.0
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/showIncludes'
-- The CXX compiler identification is Clang 3.5.0
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/showIncludes'
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: …Run Code Online (Sandbox Code Playgroud) 我使用Homebrew的最新CMake(3.9.3)以及Brew的LLVM 5.0.0,因为Clang在这里有OpenMP支持.
这适用于CMake 3.8.2和LLVM 5.
在我的CMakeLists.txt我
find_package( OpenMP )
Run Code Online (Sandbox Code Playgroud)
后来我想做
if( OpenMP_CXX_FOUND )
Run Code Online (Sandbox Code Playgroud)
然而,CMake似乎没有接受该find_package指令.
我用CMake运行
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DUSE_WERROR=ON
Run Code Online (Sandbox Code Playgroud)
我已经检查过clang并clang++正确指向/usr/local/opt/llvm/bin/clang和/usr/local/opt/llvm/bin/clang++
我得到的只是这两行:
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
Run Code Online (Sandbox Code Playgroud)
如果我OpenMP_C_FLAGS自己设置(带-DOpenMP_C_FLAGS=-fopenmp=libomp)它会将错误更改为
-- Could NOT find OpenMP_C (missing: OpenMP_C_LIB_NAMES) (found version "3.1")
Run Code Online (Sandbox Code Playgroud)
请注意,它会更改版本号,因此必须找到一些东西,对吗?
我错过了什么才能正常工作?
好吧,似乎在FindOpenMP.cmakeCMake提供的内部我们做了一个try_compile,它默默地失败了(因为我们做了很多次,而且大多数都会失败,这是有道理的).但是,使用Clang时-Werror会提供一个标志,该标志由于未使用的命令行参数而失败.我可以这样补充: …
我正在尝试使用 CMake 作为主要构建工具在 Windows 机器上构建一个简单的应用程序。一旦在项目上调用 CMake,配置阶段就会出现错误:
> cmake -H. -G Ninja -Bbuild -DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe"
-- The C compiler identification is Clang 7.0.0
-- The CXX compiler identification is Clang 7.0.0
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe --broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompile
r.cmake:52 (message):
The C compiler
"C:/Program Files/LLVM/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/mak/Desktop/cmake-test/build/CMakeFiles/CMakeTmp
Run …Run Code Online (Sandbox Code Playgroud) 我尝试让clang 5.0.0适用于Visual Studio 2015,因为我需要OpenMP 3.0功能。我安装了clang编译器(不是没有任何openmp支持的vs2015版本)并使用cmake:
cmake_minimum_required(VERSION 2.8.10)
project(myproject)
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
include_directories("include")
add_library(libFoo STATIC Foo.cpp)
install(TARGETS Foo libFoo LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试配置MSVC 14 2015 Win64带有或不带有工具链的构建时,LLVM-vs2014总是出现错误,找不到OpenMP:
The C compiler identification is Clang 5.0.0
The CXX compiler identification is Clang 5.0.0
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI …Run Code Online (Sandbox Code Playgroud)