【C++】解决googleTest报错error: SEH exception with code 0xc0000005 thrown in the test body.

简介: 【C++】解决googleTest报错error: SEH exception with code 0xc0000005 thrown in the test body.

一、报错内容

使用vs2019结合gtest做单元测试时,报错如下内容:

[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/83
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/83, where GetParam() = 83 (3 ms)
[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/84
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/84, where GetParam() = 84 (3 ms)
[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/85
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/85, where GetParam() = 85 (3 ms)
[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/86
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/86, where GetParam() = 86 (3 ms)
[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/87
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/87, where GetParam() = 87 (3 ms)
[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/88
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/88, where GetParam() = 88 (3 ms)
[ RUN      ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/89
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] kNarrow2dJointAlgorithm/FixturekNarrow2dJointThresholdSeamGray.TestThresholdSeamGray/89, where GetParam() = 89 (3 ms)

二、解决方案

在 Visual Studio 2019 中使用 GoogleTest 时遇到了这个问题。我们的设置涉及为 GoogleTest 框架创建一个库,然后将其链接到我们单独的单元测试。我最近更新了框架支持并从头开始重新编译。经过一番挖掘,发现“结构成员对齐”设置是罪魁祸首:


解决办法:项目属性 > 配置属性 > C/C++ > 代码生成 > 结构成员对齐 > 字节 /Zp1


虽然 Frameworks 项目的设置设为“默认”,但相应的 Unit Test 项目将其配置为“1 字节 /Zp1”。将更改为相同的对齐方式,重新编译后,问题就消失了。

相关文章
|
8月前
|
编译器 开发工具 C++
【Python】已解决error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build
【Python】已解决error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build
4715 0
|
5月前
|
缓存 Linux 编译器
【C++】CentOS环境搭建-安装log4cplus日志组件包及报错解决方案
通过上述步骤,您应该能够在CentOS环境中成功安装并使用log4cplus日志组件。面对任何安装或使用过程中出现的问题,仔细检查错误信息,对照提供的解决方案进行调整,通常都能找到合适的解决之道。log4cplus的强大功能将为您的项目提供灵活、高效的日志管理方案,助力软件开发与维护。
162 0
|
6月前
|
JavaScript 前端开发 测试技术
一个google Test文件C++语言案例
这篇文章我们来介绍一下真正的C++语言如何用GTest来实现单元测试。
46 0
|
7月前
|
JavaScript C++
【C++ visual studio】解决VS报错:error C2447: “{”: 缺少函数标题(是否是老式的形式表?)【亲测有效,无效捶我】
【C++ visual studio】解决VS报错:error C2447: “{”: 缺少函数标题(是否是老式的形式表?)【亲测有效,无效捶我】
264 0
|
9月前
|
Linux C++
经验分享:C++ error:‘syscall’ was not declared in this scope
经验分享:C++ error:‘syscall’ was not declared in this scope
349 3
|
9月前
|
项目管理 C++
【VS Code】安装配置调试C/C++(二)
【VS Code】安装配置调试C/C++(二)
116 1
|
22天前
|
编译器 C++ 开发者
【C++篇】深度解析类与对象(下)
在上一篇博客中,我们学习了C++的基础类与对象概念,包括类的定义、对象的使用和构造函数的作用。在这一篇,我们将深入探讨C++类的一些重要特性,如构造函数的高级用法、类型转换、static成员、友元、内部类、匿名对象,以及对象拷贝优化等。这些内容可以帮助你更好地理解和应用面向对象编程的核心理念,提升代码的健壮性、灵活性和可维护性。
|
4天前
|
安全 C++
【c++】继承(继承的定义格式、赋值兼容转换、多继承、派生类默认成员函数规则、继承与友元、继承与静态成员)
本文深入探讨了C++中的继承机制,作为面向对象编程(OOP)的核心特性之一。继承通过允许派生类扩展基类的属性和方法,极大促进了代码复用,增强了代码的可维护性和可扩展性。文章详细介绍了继承的基本概念、定义格式、继承方式(public、protected、private)、赋值兼容转换、作用域问题、默认成员函数规则、继承与友元、静态成员、多继承及菱形继承问题,并对比了继承与组合的优缺点。最后总结指出,虽然继承提高了代码灵活性和复用率,但也带来了耦合度高的问题,建议在“has-a”和“is-a”关系同时存在时优先使用组合。
30 6
|
24天前
|
编译器 C语言 C++
类和对象的简述(c++篇)
类和对象的简述(c++篇)
|
22天前
|
安全 编译器 C语言
【C++篇】深度解析类与对象(中)
在上一篇博客中,我们学习了C++类与对象的基础内容。这一次,我们将深入探讨C++类的关键特性,包括构造函数、析构函数、拷贝构造函数、赋值运算符重载、以及取地址运算符的重载。这些内容是理解面向对象编程的关键,也帮助我们更好地掌握C++内存管理的细节和编码的高级技巧。