MinGW/Cxx测试奇怪的错误

MinGW / CxxTest bizarre errors

本文关键字:错误 测试 Cxx MinGW      更新时间:2023-10-16

我希望你能帮助我。我在我的主开发机器上用CxxTest写了一个小项目。这台机器上一切都很好,没有问题。然而,我试着在我的全新笔记本电脑上设置这个项目,但就是无法实现!我怀疑我的MinGW安装而不是CxxTest出了问题,但这真的很难知道——错误源于CxxTest文件。这是项目的文件夹结构:

lib/
    cxxtest-4.3/
src/
    TestUtils.h
    test.cpp
test/
    MyTestSuite.h
    libstdc++-6.dll

在命令行上我运行:

cd test
..libcxxtest-4.3bincxxtestgen --error-printer -o runner.cpp MyTestSuite.h

这会生成runner.cpp。现在我运行:

g++ -o runner.exe runner.cpp -I "../lib/cxxtest-4.3" -std=c++11

这通常运行良好,输出runner.exe并运行我的单元测试。在我的笔记本电脑上,我只收到成千上万的错误。以下是前几个:

In file included from c:mingwincludewchar.h:208:0,
                 from c:mingwlibgccmingw324.9.3includec++cwchar:44,
                 from c:mingwlibgccmingw324.9.3includec++bitspostypes.h:40,
                 from c:mingwlibgccmingw324.9.3includec++iosfwd:40,
                 from c:mingwlibgccmingw324.9.3includec++ios:38,
                 from c:mingwlibgccmingw324.9.3includec++istream:38,
                 from c:mingwlibgccmingw324.9.3includec++sstream:38,
                 from c:mingwlibgccmingw324.9.3includec++complex:45,
                 from ../lib/cxxtest-4.3/cxxtest/StdHeaders.h:24,
                 from ../lib/cxxtest-4.3/cxxtest/StdValueTraits.h:22,
                 from ../lib/cxxtest-4.3/cxxtest/ValueTraits.h:400,
                 from ../lib/cxxtest-4.3/cxxtest/TestSuite.h:24,
                 from ../lib/cxxtest-4.3/cxxtest/RealDescriptions.h:20,
                 from ../lib/cxxtest-4.3/cxxtest/TestRunner.h:22,
                 from runner.cpp:11:
c:mingwincludesys/stat.h:173:14: error: '_dev_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: '_ino_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: '_mode_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: '_dev_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: '_off_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: 'time_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: 'time_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:173:14: error: 'time_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
c:mingwincludesys/stat.h:180:13: error: '_dev_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: '_ino_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: '_mode_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: '_dev_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: '_off_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: 'time_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: 'time_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:180:13: error: 'time_t' does not name a type
 struct stat __struct_stat_defined( _off_t, time_t );
             ^
c:mingwincludesys/stat.h:188:17: error: '_dev_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: '_ino_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: '_mode_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: '_dev_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: '__off64_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: 'time_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: 'time_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:188:17: error: 'time_t' does not name a type
 struct _stati64 __struct_stat_defined( __off64_t, time_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '_dev_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '_ino_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '_mode_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '_dev_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '__off64_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '__time64_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '__time64_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );
                 ^
c:mingwincludesys/stat.h:195:17: error: '__time64_t' does not name a type
 struct __stat64 __struct_stat_defined( __off64_t, __time64_t );

当我在一个简单的helloworld文件上运行g++时,它运行得很好。有人知道发生了什么事吗?

我最近也更新了MinGW,遇到了非常相似的问题。经过研究,我在SO上发现了这个问题,并尝试用-std=gnu++11代替-std=c++11。这为我解决了问题。希望能有所帮助!

如果您正在使用CMake,请确保您有

set( CMAKE_CXX_EXTENSIONS ON )

在您的CMakeLists.txt文件