我看过Netbeans论坛,gtest wiki&在这附近我似乎无法找到一种方法让gtest在Netbeans(6.9.1,Windows 7x64)中正常工作。我的#include of gtest.h或者单元测试文件本身没问题 - ASSERT_LE被识别等我正在使用cygwin&结果与c:\ gtest-1.5.0或cygwin / usr / local / gtest-1.5.0中的gtest相同。我认为这可能是获得一个不同的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()'
等...
如果我将自定义构建的makefile与gtest附带的makefile几乎完全相同,放入测试文件夹&右键单击它&让我得到:
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
谢谢!
答案 0 :(得分:0)
你是第一个接近 - 从“未定义的引用”的第一个片段,这是一个链接器配置问题 - 你没有添加gtest库。据我所知,gtest不会发送二进制文件,所以你必须自己编译库(gtest.lib),然后在链接器属性中的某处添加作为附加库 - 而不是自己的netbeans用户,无法准确分辨其中。