使用谷歌测试编译程序时"g++ is not a full path"
"g++ is not a full path" when compiling a program using Google Test
我正在尝试用g++编译一个使用Google Test作为子模块的程序。这是我尝试过的:
git init testgoogletest
cd testgoogletest
git submodule add https://github.com/google/googletest.git
然后,我创建了一个CMakeLists.txt其中包含:
cmake_minimum_required (VERSION 3.5.1)
project(try_googletest)
set(CMAKE_CXX_COMPILER g++)
set(VARIABLE_INCLUDE_DIR "${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
add_subdirectory(../googletest gtest)
target_include_directories(gmock_main SYSTEM BEFORE INTERFACE
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
add_executable(my_executable test.cpp)
target_link_libraries(my_executable PRIVATE gmock_main)
还有一个名为 test 的文件.cpp其中包含:
#include "gtest/gtest.h"
#include "gmock/gmock.h"
TEST(SimpleTest, works) {
EXPECT_TRUE(true);
}
然后,我运行了命令:
mkdir build
cd build
cmake ..
我得到了以下致命错误:
CMake Error at (personal path)/googletest/CMakeLists.txt:7 (project):
The CMAKE_CXX_COMPILER:
g++
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
然而,当我运行which g++
时,我得到/usr/bin/g++
这意味着编译器名称在 PATH 中,CMake 应该找到它。我什至尝试了以下方法:
- 删除谷歌测试并用空主.cpp替换测试,这完全有效,意味着问题与谷歌测试有关
- 在 CMakeList 中.txt
g++
替换为/usr/bin/g++
,在运行cmake ..
时会产生无限大的周期输出
我的问题是:
- 为什么我会收到这些错误?
- 是否存在解决方案,或者我真的需要忘记CMAKE_CXX_COMPILER并使用 CXX?
我按照你的脚步。我们确实得到了一个无限循环,以及以下输出:
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/c++
按以下方式更改文件中CMakeLists.txt
set
似乎可以解决此问题:
set(CMAKE_CXX_COMPILER /usr/bin/c++)
相关文章:
- Is !NaN not a NaN?
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- reference_wrapper导致"incomplete type is not allowed"
- 结构中的错误"Incomplete type is not allowed"
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- "Called Object Type is Not a Function or Pointer" 与 typedef 和类
- 无法创建 DLL:获取 DLL "is not a valid Win32 application"
- Atom gpp编译器给出"'C:UsersadminUser' is not recognized as an internal or..."错误
- 当我编译XG-Bosst时,出现错误"error: 'Split' is not a member of 'xgboost::common' ……"
- C++ DLL 运行时错误"abc.dll is not a valid WIN32 application" 。请帮助解决这个问题
- QString::utf16(): Is it UB or not?
- 如何修复 eigen3 中的'non-type template argument is not a constant expression'?
- 我的代码应该接受一个数字,并返回字母等级或"Grade is not valid"但 else 语句不起作用
- 如何修复此错误"the value of 'x1' is not usable in a constant expression"?static_assert
- 加载安全区图像"A device attached to the system is not functioning"
- 巴泽尔中的错误"name 'new_local_repository' is not defined"
- 如何修复 SDL2 "GLSL 3.30 is not supported"错误
- 函数模板(它是类模板的成员)的显式专用化会产生"partial specialization is not allowed"错误,为什么?