【问题标题】:Having problems with mingw32-make to make googletest使用 mingw32-make 制作 googletest 时遇到问题
【发布时间】:2019-08-19 11:57:35
【问题描述】:

这是我目前的环境。 Windows 10 64 位、MinGW、CMake 3.15.2、Python 3.7。 我从https://github.com/google/googletest下载了googletest。

我运行了cmake,输出如下。

C:\googletest-master>cd build

C:\googletest-master\build>cmake ../ -G "MinGW Makefiles"
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.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:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/Users/sangjin/AppData/Local/Programs/Python/Python37-32/python.exe (found version "3.7.4")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/googletest-master/build

但是当我运行 mingw32-make 时,我收到以下错误消息。

C:\googletest-master\build>mingw32-make
Scanning dependencies of target gtest
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from C:\googletest-master\googletest\src\gtest-all.cc:41:
C:/googletest-master/googletest/src/gtest.cc:86:11: fatal error: crtdbg.h: No such file or directory
 # include <crtdbg.h>  // NOLINT
           ^~~~~~~~~~
compilation terminated.
googletest\CMakeFiles\gtest.dir\build.make:62: recipe for target 'googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
mingw32-make[2]: *** [googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
CMakeFiles\Makefile2:171: recipe for target 'googletest/CMakeFiles/gtest.dir/all' failed
mingw32-make[1]: *** [googletest/CMakeFiles/gtest.dir/all] Error 2
Makefile:139: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

C:\googletest-master\build>

谁能帮我解决这个问题。

【问题讨论】:

  • crtdbg.h 是一个 Visual Studio 文件(请参阅here)。您是否在使用 mingw 构建之前清理了 CMake 缓存,或者为 mingw 构建使用了不同的 CMake 构建文件夹?另外,请复制/粘贴实际输出,而不是在 Stackoverflow 上使用图片/图像。
  • 我意识到了这一点,并尝试通过使用链接编辑 gtest.cc 来解决 crtdbg.h 问题,但其他与 Visual Studio 相关的头文件(例如 debugapi.h)仍然导致问题。
  • 是的,gtest.cc 文件包含crtdbg.h 标头,您可以编辑该文件以尝试解决该问题。但该标题可能包含在内是有原因的。运行 mingw 的机器上是否安装了 Visual Studio?
  • 没有。我还没有在我的机器上安装 Visual Studio。
  • 根据gtest.c 的内容,似乎假设所有Windows 环境都安装了某种形式的Visual Studio C++ 包。

标签: cmake mingw googletest


【解决方案1】:

这个版本的google test没有这个问题,尝试build一下 https://github.com/google/googletest/tree/216c37f057ae0fff38062984c890df912f40ccf6

【讨论】:

    【解决方案2】:

    这里有一个解决方案

    • mingw32-base 版本 2013072200
    • mingw32-gcc-g++版本6.3.0-1
    • gtest 版本 1.10.0

    在 ...\googletest\src\gtest.cc

    首先在(原始)第 86 行,使用 #ifdef _MSC_VER ... #endif 预处理器宏将标头包含条件设置为 MSC 工具链。

    #ifdef _MSC_VER
    # include <crtdbg.h>  // NOLINT
    # include <debugapi.h>  // NOLINT
    #endif // _MSC_VER
    

    然后在(原始)第 4913 行,使断言重定向也有条件。

    #ifdef _MSC_VER
        // In debug mode, the Windows CRT can crash with an assertion over invalid
        // input (e.g. passing an invalid file descriptor).  The default handling
        // for these assertions is to pop up a dialog and wait for user input.
        // Instead ask the CRT to dump such assertions to stderr non-interactively.
        if (!IsDebuggerPresent()) {
          (void)_CrtSetReportMode(_CRT_ASSERT,
                                  _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
          (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
        }
    #endif // _MSC_VER
    

    通过这些更改,单元测试按预期构建和执行。

    【讨论】:

      猜你喜欢
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      相关资源
      最近更新 更多