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

标签 c++ netbeans googletest

我查看了 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/

相关文章:

c++ - 根据IP和掩码打印所有IP C++

c++ - 如何在将测试 exe 与 gradle 链接时排除第二个主程序?

c++ - Googlemock:如何验证对象数组中的元素?

java - Netbeans 11.3 未安装 - java.lang.noClassDefFoundError - pack200

java - 如何使用 NetBeans 为 Java Web 应用程序生成 sun-web.xml?

c - Google 使用等待循环测试 C 函数

c++ - 在 LLVM 中获取 BasicBlock 的前身

c++ - 如何在 C++ 中使用指针翻转 Char 数组

c++ - 即使我在 QStyledItemDelegate 中设置 Qt::TextSelectableByMouse,QLabel 文本也无法选择

java - 在 NetBeans 中创建类库