- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这个问题来自 2017 年,可能已经过时了。请对提供的说明持保留态度,因为现在可能会提供更好的解决方案。
亲爱的 C++ 程序员们,
在使用 Visual Studio 工具链在 Windows 上构建一段时间后,我决定尝试一下 Clang 5。
我安装了 LLVM 5.0.0 二进制文件、Ninja 构建环境、VS 2017 工具和 CMake 3.9.3。最终目标是能够使用 VS Code 将 CMake 集成作为“IDE”,并使用 Clang 将 LLD 作为编译器和链接器,为 Windows 编译 C 和 C++ 应用程序。
一个简单程序的编译和执行工作得很好(screenshot of the respective terminal history)。 Clang 自动检测 VS 工具目录中的 Windows 标准库并生成可执行输出。
下一步是使用 Ninja ( screenshot of ninja.build file and terminal history) 设置一个简单的构建。构建过程按预期工作并生成了一个工作的可执行文件,就像以前一样。
当我开始将 CMake 集成到流程中时,问题就开始了。我的期望是 CMake 生成一个忍者构建文件并运行它,对吗?我尝试了以下 CMakeLists 文件
cmake_minimum_required(VERSION 3.9)
project(Test)
add_executable(Test main.c)
并使用 cmake -G Ninja
调用 CMake。结果输出令人失望,我对自己的理解不够清楚,无法分别解决问题。
-- 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 the following output:
Change Dir: D:/Dateien/Downloads/Test/CMakeFiles/CMakeTmp
Run Build Command:"C:/Meine_Programme/Ninja_Build/ninja.exe" "cmTC_eeb5c"
[1/2] Building C object CMakeFiles\cmTC_eeb5c.dir\testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_eeb5c.dir/testCCompiler.c.obj
C:\Meine_Programme\LLVM\bin\clang.exe /nologo /DWIN32 /D_WINDOWS /W3 /MDd
/Zi /Ob0 /Od /RTC1 /showIncludes
/FoCMakeFiles\cmTC_eeb5c.dir\testCCompiler.c.obj
/FdCMakeFiles\cmTC_eeb5c.dir\ -c testCCompiler.c
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/DWIN32'
clang.exe: error: no such file or directory: '/D_WINDOWS'
clang.exe: error: no such file or directory: '/W3'
clang.exe: error: no such file or directory: '/MDd'
clang.exe: error: no such file or directory: '/Zi'
clang.exe: error: no such file or directory: '/Ob0'
clang.exe: error: no such file or directory: '/Od'
clang.exe: error: no such file or directory: '/RTC1'
clang.exe: error: no such file or directory: '/showIncludes'
clang.exe: error: no such file or directory:
'/FoCMakeFiles\cmTC_eeb5c.dir\testCCompiler.c.obj'
clang.exe: error: no such file or directory:
'/FdCMakeFiles\cmTC_eeb5c.dir\'
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "D:/Dateien/Downloads/Test/CMakeFiles/CMakeOutput.log".
See also "D:/Dateien/Downloads/Test/CMakeFiles/CMakeError.log".
我猜这个问题与 CMake 调用 clang 和 VS 样式选项有关,使用斜杠而不是前面有减号,就像 clang 要求的那样。
谢谢你们帮我解决问题,我很感激:-)
如果您需要更多信息,请给我留言。
Florians 帖子的回复
我尝试了 Florians 命令,但省略了 ninja 的路径以获得更短的符号,结果证明它工作得很好。
cmake -E env LDFLAGS="-fuse-ld=lld" cmake -H. -G Ninja -Bbuild -DCMAKE_C_COMPILER:PATH="C:\MeineProgramme\LLVM\bin\clang.exe" -DCMAKE_CXX_COMPILER:PATH="C:\MeineProgramme\LLVM\bin\clang++.exe" -DCMAKE_C_COMPILER_ID="Clang" -DCMAKE_CXX_COMPILER_ID="Clang" -DCMAKE_SYSTEM_NAME="Generic"
CMake 生成了一个忍者构建文件。
我运行了 ninja all
以将可执行文件构建为 Test
。我把它重命名为Test.exe
,程序执行的很开心。至此……成功!!!但比我预期的要复杂得多。
最佳答案
灵感来自 "Ways to Compile with Clang on Windows"来自@Unspongeful 的博客文章,经过一些扩展测试后,以下命令行对我有用(是的,这是一个大命令,我只是分成几行以提高可读性):
> cmake -E env LDFLAGS="-fuse-ld=lld-link" PATH="<path\to\ninja>"
cmake -H. -G Ninja -Bbuild
-DCMAKE_C_COMPILER:PATH="%ProgramFiles(x86)%\LLVM\bin\clang.exe"
-DCMAKE_CXX_COMPILER:PATH="%ProgramFiles(x86)%\LLVM\bin\clang.exe"
-DCMAKE_C_COMPILER_ID="Clang"
-DCMAKE_CXX_COMPILER_ID="Clang"
-DCMAKE_SYSTEM_NAME="Generic"
这里是一些背景信息:
我用 LDFLAGS
环境变量注入(inject)了你的链接器标志
我减少了 PATH
环境变量以仅指向 ninja
所在的位置,因为 CMake 正在选择我的 MinGW
工具链(我不想将其包含在构建过程中)
与Environment variable used by CMake to detect Visual C++ compiler tools for Ninja相关
定义编译器 ID“绕过对工作编译器和基本编译器信息测试的检查”
见已过时,但有时有用 CMakeForceCompiler
module
我设置了CMAKE_SYSTEM_NAME
到 Generic
以避免 CMake 添加任何额外的特定于平台的编译器/链接器标志
参见 How to partially disabling cmake C/C++ custom compiler checking
目前看来您必须绕过许多 CMake 的自动检查才能使其正常工作。所以可能与 CMake 团队核实或 raise an issue得到这个场景的正式支持。
Generic
系统的最后一部分可能不是最佳选择,因为它会跳过 Windows 特定设置,如 .exe
后缀。
但这是唯一真正有效的星座:
-- The C compiler identification is Clang
-- The CXX compiler identification is Clang
-- Check for working C compiler: C:/Program Files (x86)/LLVM/bin/clang.exe
-- Check for working C compiler: C:/Program Files (x86)/LLVM/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/LLVM/bin/clang.exe
-- Check for working CXX compiler: C:/Program Files (x86)/LLVM/bin/clang.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: build
关于windows - 在 Windows 上使用 CMake、Ninja 和 Clang 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46553436/
运行 pip install cmake 时出现上述错误在 alpine linux (WSL) 上。 完整错误: /home/user# pip install cmake Collecting c
我的项目依赖 mariadb-connector-c我正在尝试使用 cmake 自动化下载、构建和链接过程。 我目前将项目下载到一个目录中,然后尝试执行生成忍者文件并运行它们,但我根本无法运行 cma
我正在尝试像这样在 cmake 中执行 execute_process execute_process(COMMAND ${CMAKE_COMMAND} -P myScript.cmake 这仅在文件
我想知道如果我没有给它任何变量告诉它在哪里找到它,cmake 如何找到我的 llvm cmake 配置。 我是 LLVM 新手。我正在构建一个 Hello World LLVM pass。我在 Ubu
我正在开发一个使用 CMake 的项目。顶CMakeLists.txt文件包含以下行: cmake_minimum_required(VERSION 3.7.2) # Kittens will die
我正在使用 Meego 1.2 工具链使用 cmake 运行构建(长话短说)。这个特定的工具链需要使用 --sysroot 选项来查找它需要的任何库。 set (CMAKE_CXX_FLAGS "-f
我们有一些源代码处理工具,可以从多个“片段”生成原始汇编文件等内容。 当使用 make 中的这些工具时,我们可以通过让源处理工具发出“依赖文件”来确保最新的构建,就像 gcc 一样-MD 标志。 例如
如何在 MSYS2 中安装和配置“cmake”?我尝试安装以下 MSYS 包 我在运行任何 cmake 命令时都收到以下错误 '''CMakeLists.txt:5 (cmake_minimum_re
有没有办法在 CMake 中得到一个变量列表?具体来说,我想要做的是调用一个现有函数,该函数接受多个变量并检查它们的计算结果是否为 true。 在某些情况下,其中一些变量将是空列表(计算结果为 fal
我有两组测试(功能测试和单元测试),我希望能够指定通过 cmake 运行哪一组。 一组测试是我想通过“make test”运行的单元测试。 另一组测试是我想通过“制作功能测试”来运行的功能测试。 目前
我的目标是查看有关调用 g++ 的详细信息由 cmake 直接调用从命令行。我不关心 make 的输出就这个问题而言。 根据official FAQ和 the accepted answer on a
我有一个生成库的CMake项目。我已经编写了一个CMake脚本FindXXX.cmake来帮助我的图书馆的用户。这样,他们可以使用find_package(XXX)并获取所需的变量。到现在为止还挺好。
当我看到带有命名空间的 CMake 库时,它们总是在表单中Parent::Component . 如果我有一个足够大的库,那么该库的子部分可能包含组件。我想知道是否可以/适合做 ParentProje
CMake 变量和属性似乎完成了非常相似的事情,我一直无法理解它们之间的区别。 它们每个都有自己的文档部分,但两者都会影响构建系统,两者都是“预先存在的”,并且两者都可以基于其他 CMake 命令动态
我有一个包含多个子目录的 CMake 项目,例如: dir1 subdir11 subdir12 dir2 subdir21 subdir22 根 CMakeLists
如果您想将静态库链接到共享库或可执行文件,同时保持所有符号可见(例如,您可以稍后打开它以找到它们),在 Linux/BSD 上执行此操作的一种非可移植方式是使用标志-Wl,--whole-archiv
CMake 自动创建一个 FooTarget.cmake文件例如添加 install(EXPORT FooTargets FILE FooTargets.cmake NAMESPACE Foo
在CMake中,ELSE和ENDIF控制流函数将表达式作为参数。根据文档,这些是optional。那么这些目的是什么?仅仅是为了维护目的而使原始IF表达式更清晰,还是提供某些功能? 最佳答案 正如您所
我是 cmake 的新手,我发现它非常令人沮丧。我试图在构建运行时评估的文件路径中使用通配符,而不是在生成构建时。 我创建了一个构建,它使用 SWIG 为某些 C++ 代码生成 Java 包装器。我可
我可能在谷歌上搜索错误,但我无法找到 .cmake 文件的用途。 我刚刚偶然发现了一个我必须使用的项目的 CMake 工具,我很难理解它是如何工作的。我明白在包含 CMakeLists.txt 的目录
我是一名优秀的程序员,十分优秀!