2

CMake 没有找到 clang rc 编译器。可以为cmake设置它,使其运行成功,但是ninja在尝试编译gtest时会失败。

您好,我正在尝试使用 Ninja、CMake 和 Clang 建立一个简单的测试项目。

我正在运行 Windows 10 pro 环境并安装了以下版本:

  • 铿锵声:8.0.0
  • CMake:3.15.0-rc1
  • 忍者:1.9.0

我试图:

  • 通过命令行设置rc编译器。
  • 使用 CMakeLists.txt 中的 set 命令设置 rc 编译器。

这让我通过了第一次 cmake 运行,但是当运行 ninja 时,它在 gtest 项目上第二次在内部调用 cmake 并失败并出现相同的错误。

我不想分叉 gtest 项目或更改 cmakecache 文件。

CMakeFile.txt

cmake_minimum_required (VERSION 3.1)

# this does not fix it.
# set("RC" "llvm-rc")

# running cmake with -D CMAKE_RC_COMPILER="llvm-rc"

project (ExampleProject)

# setup cmake extensions.
include(ExternalProject)

# setup project configuration.

set (ExampleProject_VERSION_MAJOR 0)
set (ExampleProject_VERSION_MINOR 0)

set (CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# configure cmake variables.

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)

# install gtest.

ExternalProject_Add(googletest
    GIT_REPOSITORY https://github.com/google/googletest
    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)

# include extensions.
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

add_executable(run main.cxx)

主文件

#include <iostream>

int main(int arcv, char** argv) {
    std::cout << "Hello world!" << std::endl;
}

要构建它,我目前使用以下命令:

cmake -G Ninja -B build .
cd build
ninja

我希望编译器链能够成功编译项目并创建一个二进制文件,该文件将输出:“Hello world!”。

目前它在主项目中或构建 gtest 时找不到 rc 编译器而失败。

它输出以下消息:

C:\Users\HP\Desktop\projekte\testproject>cmake -GNinja -Bbuild .
-- The C compiler identification is Clang 8.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 8.0.0 with GNU-like command-line
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:81 (enable_language):
  No CMAKE_RC_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "RC" or the CMake cache entry CMAKE_RC_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:121 (__windows_compiler_clang_gnu)
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang-C.cmake:2 (__windows_compiler_clang)
  C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeCInformation.cmake:48 (include)
  CMakeLists.txt:8 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/HP/Desktop/projekte/testproject/build/CMakeFiles/CMakeOutput.log".

或者它使用 rc 编译器集输出:

C:\Users\HP\Desktop\projekte\testproject>cmake -GNinja -Bbuild . -DCMAKE_RC_COMPILER=llvm-rc
-- The C compiler identification is Clang 8.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 8.0.0 with GNU-like command-line
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe
-- Check for working C compiler: C:/Program Files/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/LLVM/bin/clang++.exe
-- Check for working CXX compiler: C:/Program Files/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: C:/Users/HP/Desktop/projekte/testproject/build

C:\Users\HP\Desktop\projekte\testproject>cd build

C:\Users\HP\Desktop\projekte\testproject\build>ninja
[4/10] Performing download step (git clone) for 'googletest'
Cloning into 'googletest'...
Already on 'master'
Your branch is up to date with 'origin/master'.
[6/10] Performing update step for 'googletest'
Current branch master is up to date.
[7/10] Performing configure step for 'googletest'
FAILED: googletest-prefix/src/googletest-stamp/googletest-configure
cmd.exe /C "cd /D C:\Users\HP\Desktop\projekte\testproject\build\googletest-prefix\src\googletest-build && "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_INSTALL_PREFIX=C:/Users/HP/Desktop/projekte/testproject/build/external -GNinja C:/Users/HP/Desktop/projekte/testproject/build/googletest-prefix/src/googletest && "C:\Program Files\CMake\bin\cmake.exe" -E touch C:/Users/HP/Desktop/projekte/testproject/build/googletest-prefix/src/googletest-stamp/googletest-configure"
-- The C compiler identification is Clang 8.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 8.0.0 with GNU-like command-line
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:81 (enable_language):
  No CMAKE_RC_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "RC" or the CMake cache entry CMAKE_RC_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:121 (__windows_compiler_clang_gnu)
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang-C.cmake:2 (__windows_compiler_clang)
  C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeCInformation.cmake:48 (include)
  CMakeLists.txt:10 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/HP/Desktop/projekte/testproject/build/googletest-prefix/src/googletest-build/CMakeFiles/CMakeOutput.log".
ninja: build stopped: subcommand failed.

C:\Users\HP\Desktop\projekte\testproject\build>
4

1 回答 1

1

它真的很简单。您可以在 externalProject_Add 命令中设置 cmake_args。

ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest
CMAKE_ARGS -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER}
)

如何为 CMAKE 外部项目指定编译器?

我参考了位于以下位置的手册以获取更多信息:https ://cmake.org/cmake/help/latest/module/ExternalProject.html

于 2019-07-26T22:41:19.007 回答