[英]“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應該找到它。 我什至嘗試了以下方法:
/usr/bin/g++
替換CMakeLists.txt g++
,運行cmake ..
時會產生無限大的周期性輸出cmake ..
我的問題是:
我按照你的步驟。 我們確實得到了一個無限循環,以及以下輸出:
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++)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.