首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >忍者:找不到CMAKE_RC_COMPILER

忍者:找不到CMAKE_RC_COMPILER
EN

Stack Overflow用户
提问于 2019-07-26 19:40:49
回答 1查看 3K关注 0票数 2

CMake没有找到clang编译器。可以为cmake设置它,这使它成功运行,但是忍者在编译gtest时会失败。

你好,我试图建立一个简单的测试项目使用忍者,CMake和Clang。

我正在运行一个windows 10 pro环境,并安装了以下版本:

  • Clang: 8.0.0
  • CMake: 3.15.0-rc1
  • 忍者: 1.9.0

我试图:

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

这允许我传递第一个cmake运行,但是当运行ninja时,它在gtest项目上第二次调用cmake,并以相同的错误失败。

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

CMakeFile.txt

代码语言:javascript
运行
复制
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)

main.cxx

代码语言:javascript
运行
复制
#include <iostream>

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

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

代码语言:javascript
运行
复制
cmake -G Ninja -B build .
cd build
ninja

我期望编译器链成功地编译该项目,并创建一个二进制文件,该文件将输出:"Hello!“。

目前,它无法在主项目中或在构建gtest时找到rc编译器。

它输出以下信息:

代码语言:javascript
运行
复制
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编译器集输出:

代码语言:javascript
运行
复制
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>
EN

回答 1

Stack Overflow用户

发布于 2019-07-26 22:41:19

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

代码语言:javascript
运行
复制
ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest
CMAKE_ARGS -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER}
)

How to specify the compiler for CMAKE external project?

有关更多信息,我参考了位于:https://cmake.org/cmake/help/latest/module/ExternalProject.html的手册。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57226146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档