[英]“g++ is not a full path” when compiling a program using Google Test
I am trying to compile with g++ a program that uses Google Test as a submodule. 我正在尝试使用g ++编译使用Google Test作为子模块的程序。 Here is what I tried:
这是我尝试过的:
git init testgoogletest
cd testgoogletest
git submodule add https://github.com/google/googletest.git
Then, I created a CMakeLists.txt containing: 然后,我创建了一个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)
And a file named test.cpp containing: 还有一个名为test.cpp的文件,其中包含:
#include "gtest/gtest.h"
#include "gmock/gmock.h"
TEST(SimpleTest, works) {
EXPECT_TRUE(true);
}
Then, I ran the commands: 然后,我运行了命令:
mkdir build
cd build
cmake ..
And I got the following fatal error: 而且我遇到了以下致命错误:
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.
Yet, when I run which g++
, I get /usr/bin/g++
which means that the compiler name is in the PATH and that CMake should find it. 但是,当我运行
which g++
,我得到了/usr/bin/g++
,这意味着编译器名称在PATH中,并且CMake应该找到它。 I even tried the following: 我什至尝试了以下方法:
g++
with /usr/bin/g++
, which produces an infinitely large periodic output when running cmake ..
/usr/bin/g++
替换CMakeLists.txt g++
,运行cmake ..
时会产生无限大的周期性输出cmake ..
My questions are: 我的问题是:
I followed your steps. 我按照你的步骤。 We indeed get an infinite loop, and the following output:
我们确实得到了一个无限循环,以及以下输出:
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++
Changing the set
in CMakeLists.txt
file in the following way appears to fix this: 以以下方式更改
CMakeLists.txt
文件中的set
似乎可以解决此问题:
set(CMAKE_CXX_COMPILER /usr/bin/c++)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.