使用 mingw-w64 编译 cpputest



我正在尝试使用 mingw-w64 编译 cpputest,但无法使其工作,我找不到有关如何执行此操作的任何资源。所以希望这个问题将来能帮助其他人。

我想使用 mingw-w64 编译 cpputest,最好不安装 MSYS2 或其他软件包。

我安装了 mingw-w64 i686-8.1.0-posix-dwarf-rt_v6-rev0。我从这里克隆了 cpputest。

我尝试使用 Mingw-w64 编译 Google 测试,并通过调用 CMake 在 MSYS2/MinGW32 下编译和使用 CppUTest 3.8

cmake ^
-G "MinGW Makefiles" ^
-D CMAKE_C_COMPILER=gcc.exe ^
-D CMAKE_CXX_COMPILER=g++.exe ^
-D CMAKE_MAKE_PROGRAM=mingw32-make.exe ^
-D C++11=ON ^
.

这会产生:

-------------------------------------------------------
CppUTest Version 3.8
Current compiler options:
CC:                                 C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe
CXX:                                C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe
CppUTest CFLAGS:                     -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"  -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Wstrict-prototypes
CppUTest CXXFLAGS:                   -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"    -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast -Wno-c++14-compat
CppUTest LDFLAGS:
Features configured in CppUTest:
Memory Leak Detection:              ON
Compiling Extensions:               ON
Support Long Long:                  OFF
Use CppUTest flags:                 ON
Using Standard C library:           ON
Using Standard C++ library:         ON
Using C++11 library:                ON
Generating map file:                OFF
Compiling with coverage:            OFF
Compile and run self-tests          ON
Run self-tests separately           OFF
-------------------------------------------------------

运行生成失败,并显示:

>mingw32-make.exe
Scanning dependencies of target CppUTest
[  1%] Building CXX object src/CppUTest/CMakeFiles/CppUTest.dir/CommandLineArguments.cpp.obj
In file included from C:/git/tdd/cpputest/include/CppUTest/Utest.h:34,
from C:/git/tdd/cpputest/include/CppUTest/TestHarness.h:39,
from C:gittddcpputestsrcCppUTestCommandLineArguments.cpp:29:
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:183:31: error: 'nullptr_t' does not name a type
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:183:31: note: 'nullptr_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:42:1:
+#include <cstddef>
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:183:31:
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
mingw32-make.exe[2]: *** [srcCppUTestCMakeFilesCppUTest.dirbuild.make:63: src/CppUTest/CMakeFiles/CppUTest.dir/CommandLineArguments.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:886: src/CppUTest/CMakeFiles/CppUTest.dir/all] Error 2
mingw32-make.exe: *** [Makefile:140: all] Error 2

我尝试了将cstddef添加到SimpleString.h的明显解决方案:

--- a/include/CppUTest/SimpleString.h                                                
+++ b/include/CppUTest/SimpleString.h                                                
@@ -180,6 +180,9 @@ SimpleString BracketsFormattedHexString(SimpleString hexString); 
* Specifically nullptr_t is not officially supported                               
*/                                                                                 
#if __cplusplus > 199711L && !defined __arm__                                       
+                                                                                    
+#include <cstddef>                                                                  
+                                                                                    
SimpleString StringFrom(const nullptr_t value);                                     
#endif                                                                              

但这仍然失败并出现相同的错误。

所以我尝试通过安装 MSYS2 然后安装 mingw-w64、CMake 和Ninja 来遵循 CMake 和 MSYS2 mingw-w64 的构建错误。这给出了:

-------------------------------------------------------
CppUTest Version 3.8
Current compiler options:
CC:                                 C:/msys64/mingw64/bin/cc.exe
CXX:                                C:/msys64/mingw64/bin/c++.exe
CppUTest CFLAGS:                     -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"  -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Wstrict-prototypes
CppUTest CXXFLAGS:                   -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"  -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast
CppUTest LDFLAGS:
Features configured in CppUTest:
Memory Leak Detection:              ON
Compiling Extensions:               ON
Support Long Long:                  OFF
Use CppUTest flags:                 ON
Using Standard C library:           ON
Using Standard C++ library:         ON
Using C++11 library:                OFF
Generating map file:                OFF
Compiling with coverage:            OFF
Compile and run self-tests          ON
Run self-tests separately           OFF
-------------------------------------------------------

使用cmake -G Ninja . && ninja编译失败,并显示:

include/CppUTest/SimpleString.h:183:31:
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
[10/98] Building CXX object src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj
FAILED: src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj
C:msys64mingw64binc++.exe  -DCPPUTEST_HAVE_STRDUP=1 -DHAVE_CONFIG_H -D_TIMESPEC_DEFINED=1 -I. -Iinclude -Isrc/CppUTest/../../include -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"  -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast -O2 -g -DNDEBUG -MD -MT src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj -MF srcCppUTestCMakeFilesCppUTest.dirTestMemoryAllocator.cpp.obj.d -o src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj -c src/CppUTest/TestMemoryAllocator.cpp
In file included from include/CppUTest/Utest.h:34,
from include/CppUTest/TestHarness.h:39,
from src/CppUTest/TestMemoryAllocator.cpp:28:
include/CppUTest/SimpleString.h:183:31: error: 'nullptr_t' does not name a type
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
include/CppUTest/SimpleString.h:183:31: note: 'nullptr_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
include/CppUTest/SimpleString.h:42:1:
+#include <cstddef>
include/CppUTest/SimpleString.h:183:31:
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
ninja: build stopped: subcommand failed.

谢谢!!

事实证明,这是CppUtest中的一个错误。

@@ -562,7 +562,7 @@ SimpleString BracketsFormattedHexString(SimpleString hexString)
* Specifically nullptr_t is not officially supported
*/
#if __cplusplus > 199711L && !defined __arm__
- SimpleString StringFrom(const nullptr_t value)
+ SimpleString StringFrom(const std::nullptr_t value)
{
(void) value;
return "(null)";

自 2019 年 12 月 5 日起修复。

https://github.com/leonardopsantos/cpputest/commit/cb8c457dda6741ede7009103db99967b5f27c969

最新更新