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

请添加图片描述


👉博__主👈:米码收割机
👉技__能👈:C++/Python语言
👉公众号👈:测试开发自动化【获取源码+商业合作】
👉荣__誉👈:阿里云博客专家博主、51CTO技术博主
👉专__注👈:专注主流机器人、人工智能等相关领域的开发、测试技术。


系列文章目录



一、报错内容

使用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”。将更改为相同的对齐方式,重新编译后,问题就消失了。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

米码收割机

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值