gpt4 book ai didi

c++ - 如何在 Windows Netbeans 中设置 gtest?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:01:38 30 4
gpt4 key购买 nike

我查看了 Netbeans 论坛、gtest wiki 以及附近的内容,我似乎无法找到让 gtest 在 Netbeans(6.9.1,Windows 7x64)中正常工作的方法。我的 gtest.h 的 #include 或 unittest 文件本身没有问题 - ASSERT_LE 被识别等。我使用的是 cygwin,结果与 c:\gtest-1.5.0 或 cygwin/usr/的 gtest 相同本地/gtest-1.5.0。我认为可能需要为测试获取不同的 makefile 以使用 & 基于 gtest 包含的 makefile,但这对我没有用(也许我做错了)。这是我按下 ALT-F6(测试项目)时得到的结果:


g++.exe -o build/Debug/Cygwin-Windows/tests/TestFiles/f1 build/Debug/Cygwin-Windows/tests/tests/Armor_unittest.o build/Debug/Cygwin-Windows/tests/tests/newsimpletest.o build/Debug/Cygwin-Windows/main_nomain.o build/Debug/Cygwin-Windows/Character_nomain.o build/Debug/Cygwin-Windows/Map_nomain.o build/Debug/Cygwin-Windows/Armor_nomain.o build/Debug/Cygwin-Windows/Weapon_nomain.o build/Debug/Cygwin-Windows/Shop_nomain.o build/Debug/Cygwin-Windows/Enemy_nomain.o
build/Debug/Cygwin-Windows/tests/tests/Armor_unittest.o: In function `_ZN31ArmorTest_SetupAndGetWorks_Test8TestBodyEv':
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'

等...

如果我将一个与 gtest 中包含的几乎相同的自定义生成文件放入测试文件夹并右键单击它并制作我得到:

Makefile:21: target `gtest-all.o' doesn't match the target pattern
Makefile:25: target `gtest_main.o' doesn't match the target pattern
Makefile:39: *** multiple target patterns. Stop.

如果我再次执行测试项目,我会得到:


rm -f build/Debug/Cygwin-Windows/tests/tests/Makefile.o.d
g++.exe -c -g -I../../../../../../../gtest-1.5.0/include -MMD -MP -MF build/Debug/Cygwin-Windows/tests/tests/Makefile.o.d -o build/Debug/Cygwin-Windows/tests/tests/Makefile.o tests/Makefile
g++: tests/Makefile: linker input file unused because linking not done
gcc.exe build/Debug/Cygwin-Windows/tests/tests/Makefile.o -o build/Debug/Cygwin-Windows/tests/tests/Makefile
gcc: build/Debug/Cygwin-Windows/tests/tests/Makefile.o: No such file or directory
gcc: no input files
make[1]: *** [build/Debug/Cygwin-Windows/tests/tests/Makefile] Error 1
make[1]: Leaving directory `/cygdrive/c/Users/.../winPro2Game'
make: *** [.build-tests-impl] Error 2

谢谢!

最佳答案

您一开始就很接近 - 从“ undefined reference ”的第一个片段开始,这是一个链接器配置问题 - 您没有添加 gtest 库。据我所知,gtest 不提供二进制文件,因此您必须自己编译库 (gtest.lib),然后将其作为附加库添加到链接器属性中的某处——我自己不是 netbeans 用户,无法准确说出哪里。

关于c++ - 如何在 Windows Netbeans 中设置 gtest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5287185/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com