从终端使用 GoogleTest 项目构建 CLion CMake

问题描述 投票:0回答:1

我可以在 CLion 中使用 GoogleTest 构建 CMake 项目。但我无法从终端构建它。在将 GoogleTest 构建为依赖项时,我遇到了很多错误。我还尝试在没有 GoogleTest 的情况下从终端构建项目,效果很好。
平台:Windows 11 x64

主根CMakeList.txt

cmake_minimum_required (VERSION 3.8)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(COMMON_PROJECT_CPP_STANDARD 20 ON CACHE BOOL "" FORCE)
set(CMAKE_CXX_STANDARD 20)

include(FetchContent)
FetchContent_Declare(
  googletest
  URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.zip
  DOWNLOAD_EXTRACT_TIMESTAMP ON
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

project ("DataStructuresAndAlgorithms")
enable_testing()
add_subdirectory ("src/BubbleSort")

冒泡排序 CMakeList.txt

project("BubbleSort")
add_executable(
    ${PROJECT_NAME}
    "bubblesort.test.cpp"
    "bubblesort.h"
)
if (CMAKE_VERSION VERSION_GREATER 3.12)
    set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD ${COMMON_PROJECT_CPP_STANDARD})
endif()
# GoogleTest requires at least C++14
target_link_libraries(
    ${PROJECT_NAME}
    GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME})

我从 CLion 构建输出中复制了命令并尝试了它们。
配置项目

PS D:\0my\pr0jects\CnC++\DataStructuresAndAlgorithms> cmake.exe -DCMAKE_MAKE_PROGRAM="E:/Programs/JetBrains/CLion 2023.1.1/bin/ninja/win/x64/ninja.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=--coverage -DCMAKE_C_FLAGS=--coverage -G Ninja -S D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms -B D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: E:/Programs/MinGW/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: E:/Programs/MinGW/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: E:/Programs/Python/Python311/python.exe (found version "3.11.3") found components: Interpreter
-- Configuring done (6.9s)
-- Generating done (0.1s)
-- Build files have been written to: D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage

构建

PS D:\0my\pr0jects\CnC++\DataStructuresAndAlgorithms> cmake.exe --build D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage --target all -j 6
[1/24] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
FAILED: _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
E:\Programs\MinGW\bin\c++.exe  -isystem D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include -isystem D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest --coverage -g -std=c++2a -Wall -Wshadow -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=0 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -MD -MT _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -MF _deps\googletest-build\googletest\CMakeFiles\gtest_main.dir\src\gtest_main.cc.obj.d -o _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -c D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/src/gtest_main.cc
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/src/gtest_main.cc:32:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1257:8: error: 'mutex' in namespace 'std' does not name a type
 1257 |   std::mutex mu_;
      |        ^~~~~
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/src/gtest_main.cc:32:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:773:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
  772 | #include <mutex>               // NOLINT
  +++ |+#include <mutex>
  773 | #endif                         // GTEST_IS_THREADSAFE
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/src/gtest_main.cc:32:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1258:8: error: 'condition_variable' in namespace 'std' does not name a type
 1258 |   std::condition_variable cv_;
      |        ^~~~~~~~~~~~~~~~~~
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/src/gtest_main.cc:32:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:773:1: note: 'std::condition_variable' is defined in header '<condition_variable>'; did you forget to '#include <condition_variable>'?
  772 | #include <mutex>               // NOLINT
  +++ |+#include <condition_variable>
  773 | #endif                         // GTEST_IS_THREADSAFE
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/src/gtest_main.cc:32:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In member function 'void testing::internal::Notification::Notify()':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:26: error: 'mutex' is not a member of 'std'
 1244 |     std::lock_guard<std::mutex> lock(mu_);
      |                          ^~~~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:26: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:31: error: template argument 1 is invalid
 1244 |     std::lock_guard<std::mutex> lock(mu_);
      |                               ^
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:38: error: 'mu_' was not declared in this scope
 1244 |     std::lock_guard<std::mutex> lock(mu_);
      |                                      ^~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1246:5: error: 'cv_' was not declared in this scope
 1246 |     cv_.notify_all();
      |     ^~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In member function 'void testing::internal::Notification::WaitForNotification()':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1252:27: error: 'mutex' is not a member of 'std'
 1252 |     std::unique_lock<std::mutex> lock(mu_);
      |                           ^~~~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1252:27: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1252:32: error: template argument 1 is invalid
 1252 |     std::unique_lock<std::mutex> lock(mu_);
      |                                ^
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1252:39: error: 'mu_' was not declared in this scope
 1252 |     std::unique_lock<std::mutex> lock(mu_);
      |                                       ^~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1253:5: error: 'cv_' was not declared in this scope
 1253 |     cv_.wait(lock, [this]() { return notified_; });
      |     ^~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1992:40: error: '_fileno' was not declared in this scope; did you mean 'file'?
 1992 | inline int FileNo(FILE* file) { return _fileno(file); }
      |                                        ^~~~~~~
      |                                        file
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2044:10: error: '_stricmp' was not declared in this scope; did you mean 'strncmp'?
 2044 |   return _stricmp(s1, s2);
      |          ^~~~~~~~
      |          strncmp
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2046:47: error: '_strdup' was not declared in this scope
 2046 | inline char* StrDup(const char* src) { return _strdup(src); }
      |                                               ^~~~~~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2106:56: error: 'fdopen' was not declared in this scope; did you mean 'fopen'?
 2106 | inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
      |                                                        ^~~~~~
      |                                                        fopen
[2/24] Building CXX object src/Algorithms/Sort/BubbleSort/CMakeFiles/BubbleSort.dir/bubblesort.test.cpp.obj
FAILED: src/Algorithms/Sort/BubbleSort/CMakeFiles/BubbleSort.dir/bubblesort.test.cpp.obj
E:\Programs\MinGW\bin\c++.exe  -ID:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/common -ID:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/ON -isystem D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include -isystem D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest --coverage -g -std=gnu++2a -MD -MT src/Algorithms/Sort/BubbleSort/CMakeFiles/BubbleSort.dir/bubblesort.test.cpp.obj -MF src\Algorithms\Sort\BubbleSort\CMakeFiles\BubbleSort.dir\bubblesort.test.cpp.obj.d -o src/Algorithms/Sort/BubbleSort/CMakeFiles/BubbleSort.dir/bubblesort.test.cpp.obj -c D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/bubblesort.test.cpp
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/bubblesort.test.cpp:1:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1257:8: error: 'mutex' in namespace 'std' does not name a type
 1257 |   std::mutex mu_;
      |        ^~~~~
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/bubblesort.test.cpp:1:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:773:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
  772 | #include <mutex>               // NOLINT
  +++ |+#include <mutex>
  773 | #endif                         // GTEST_IS_THREADSAFE
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/bubblesort.test.cpp:1:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1258:8: error: 'condition_variable' in namespace 'std' does not name a type
 1258 |   std::condition_variable cv_;
      |        ^~~~~~~~~~~~~~~~~~
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/bubblesort.test.cpp:1:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:773:1: note: 'std::condition_variable' is defined in header '<condition_variable>'; did you forget to '#include <condition_variable>'?
  772 | #include <mutex>               // NOLINT
  +++ |+#include <condition_variable>
  773 | #endif                         // GTEST_IS_THREADSAFE
In file included from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-message.h:57,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/gtest.h:64,
                 from D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/src/Algorithms/Sort/BubbleSort/bubblesort.test.cpp:1:
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In member function 'void testing::internal::Notification::Notify()':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:26: error: 'mutex' is not a member of 'std'
 1244 |     std::lock_guard<std::mutex> lock(mu_);
      |                          ^~~~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:26: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:31: error: template argument 1 is invalid
 1244 |     std::lock_guard<std::mutex> lock(mu_);
      |                               ^
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1244:38: error: 'mu_' was not declared in this scope
 1244 |     std::lock_guard<std::mutex> lock(mu_);
      |                                      ^~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1246:5: error: 'cv_' was not declared in this scope
 1246 |     cv_.notify_all();
      |     ^~~
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In member function 'void testing::internal::Notification::WaitForNotification()':
D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:1252:27: error: 'mutex' is not a member of 'std'
 1252 |     std::unique_lock<std::mutex> lock(mu_);
      |                           ^~~~~
...
ninja: build stopped: subcommand failed.
PS D:\0my\pr0jects\CnC++\DataStructuresAndAlgorithms>

当我尝试使用与 CLion 中相同的工具链时,出现下一个错误。 配置项目

PS D:\0my\pr0jects\CnC++\DataStructuresAndAlgorithms> ."E:/Programs/JetBrains/CLion 2023.1.1/bin/cmake/win/x64/bin/cmake.exe" -DCMAKE_MAKE_PROGRAM="E:/Programs/JetBrains/CLion 2023.1.1/bin/ninja/win/x64/ninja.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="E:/Programs/JetBrains/CLion 2023.1.1/bin/mingw/bin/gcc.exe" -DCMAKE_CXX_COMPILER="E:/Programs/JetBrains/CLion 2023.1.1/bin/mingw/bin/g++.exe" -G Ninja -S D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms -B D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: E:/Programs/JetBrains/CLion 2023.1.1/bin/mingw/bin/gcc.exe
-- Check for working C compiler: E:/Programs/JetBrains/CLion 2023.1.1/bin/mingw/bin/gcc.exe - broken
CMake Error at E:/Programs/JetBrains/CLion 2023.1.1/bin/cmake/win/x64/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message):
  The C compiler

    "E:/Programs/JetBrains/CLion 2023.1.1/bin/mingw/bin/gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/CMakeFiles/CMakeScratch/TryCompile-zurrzv

    Run Build Command(s):E:/Programs/JetBrains/CLion 2023.1.1/bin/ninja/win/x64/ninja.exe cmTC_dc730 && [1/2] Building C object CMakeFiles\cmTC_dc730.dir\testCCompiler.c.obj
    FAILED: CMakeFiles/cmTC_dc730.dir/testCCompiler.c.obj
    "E:\Programs\JetBrains\CLion 2023.1.1\bin\mingw\bin\gcc.exe"    -o CMakeFiles\cmTC_dc730.dir\testCCompiler.c.obj -c D:\0my\pr0jects\CnC++\DataStructuresAndAlgorithms\mybuild\x64-win-debug-mingw-coverage\CMakeFiles\CMakeScratch\TryCompile-zurrzv\testCCompiler.c
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  mybuild/x64-win-debug-mingw-coverage/_deps/googletest-src/CMakeLists.txt:18 (project)

-- Configuring incomplete, errors occurred!
See also "D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/CMakeFiles/CMakeOutput.log".
See also "D:/0my/pr0jects/CnC++/DataStructuresAndAlgorithms/mybuild/x64-win-debug-mingw-coverage/CMakeFiles/CMakeError.log".

更新: 我的主要问题/目标是从终端使用 GoogleTest 编译 CLion 项目。如何完成、使用什么工具链 - 对我来说并不重要。

为什么这篇文章被评为不清楚,没有一个具体的建议来解决问题或疑问,到底是什么不清楚?

c++ cmake mingw clion googletest
1个回答
0
投票

从错误信息来看:

error: 'mutex' in namespace 'std' does not name a type

这表明您的 MinGW 系统范围安装没有 posix。请参阅 命名空间 std 中的 C++ 互斥体未命名类型

© www.soinside.com 2019 - 2024. All rights reserved.