2

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. gtest に含まれる makefile に基づいて、テストで使用する別の 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 を test フォルダーに配置し、それを右クリックして Make I を取得すると、次のようになります。

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.

Test Project をもう一度実行すると、次のようになります。


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

ありがとう!

4

1 に答える 1

0

「未定義の参照」の最初のスニペットから、それはリンカーの構成の問題です-gtestライブラリが追加されていません。私が覚えている限り、gtest はバイナリを出荷していないので、自分でライブラリ (gtest.lib) をコンパイルする必要があります。それから、リンカ プロパティのどこかに追加のライブラリとして追加する必要があります。どこ。

于 2011-12-05T17:52:02.500 に答える