Error compiling test file with visual studio

659 views
Skip to first unread message

iiHeppa

unread,
Oct 20, 2008, 12:46:13 PM10/20/08
to Google C++ Testing Framework
Hi, I'm a beginner in C++ and Visual Studio.
I have a problem wirh a simple test file:

#include <gtest/gtest.h>

TEST(Test, One) {
EXPECT_EQ(2, 1+1);
}

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

I get the following error: I tried to link with the lib files in msvc/
debug I build with Visual studio
(sorry for the german text, but I think the problem is clear)

------ Erstellen gestartet: Projekt: googleTest, Konfiguration: Debug
Win32 ------
Kompilieren...
googleTest.cc
Verknüpfen...
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""public: void __thiscall
testing::internal::AssertHelper::operator=(class testing::Message
const &)const " (??
4AssertHelper@internal@testing@@QBEXABVMessage@2@@Z)" in Funktion
""private: virtual void __thiscall Test_One_Test::TestBody(void)" (?
TestBody@Test_One_Test@@EAEXXZ)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""public: __thiscall
testing::internal::AssertHelper::AssertHelper(enum
testing::TestPartResultType,char const *,int,char const *)" (??
0AssertHelper@internal@testing@@QAE@W4TestPartResultType@2@PBDH1@Z)"
in Funktion ""private: virtual void __thiscall
Test_One_Test::TestBody(void)" (?TestBody@Test_One_Test@@EAEXXZ)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""public: int __thiscall testing::UnitTest::Run(void)" (?
Run@UnitTest@testing@@QAEHXZ)" in Funktion "_main".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""public: static class testing::UnitTest * __cdecl
testing::UnitTest::GetInstance(void)" (?
GetInstance@UnitTest@testing@@SAPAV12@XZ)" in Funktion "_main".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""void __cdecl testing::InitGoogleTest(int *,char * *)" (?
InitGoogleTest@testing@@YAXPAHPAPAD@Z)" in Funktion "_main".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""class testing::AssertionResult __cdecl
testing::internal::EqFailure(char const *,char const *,class
testing::internal::String const &,class testing::internal::String
const &,bool)" (?EqFailure@internal@testing@@YA?
AVAssertionResult@2@PBD0ABVString@12@1_N@Z)" in Funktion ""class
testing::AssertionResult __cdecl
testing::internal::CmpHelperEQ<int,int>(char const *,char const *,int
const &,int const &)" (??$CmpHelperEQ@HH@internal@testing@@YA?
AVAssertionResult@1@PBD0ABH1@Z)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""class testing::AssertionResult __cdecl
testing::AssertionSuccess(void)" (?AssertionSuccess@testing@@YA?
AVAssertionResult@1@XZ)" in Funktion ""class testing::AssertionResult
__cdecl testing::internal::CmpHelperEQ<int,int>(char const *,char
const *,int const &,int const &)" (??
$CmpHelperEQ@HH@internal@testing@@YA?AVAssertionResult@1@PBD0ABH1@Z)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""class testing::internal::String __cdecl
testing::internal::StrStreamToString(class
std::basic_stringstream<char,struct std::char_traits<char>,class
std::allocator<char> > *)" (?StrStreamToString@internal@testing@@YA?
AVString@12@PAV?$basic_stringstream@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z)" in Funktion ""public: class
testing::internal::String __thiscall
testing::Message::GetString(void)const " (?
GetString@Message@testing@@QBE?AVString@internal@2@XZ)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""class testing::TestInfo * __cdecl
testing::internal::MakeAndRegisterTestInfo(char const *,char const
*,char const *,char const *,void *,void (__cdecl*)(void),void
(__cdecl*)(void),class testing::internal::TestFactoryBase *)" (?
MakeAndRegisterTestInfo@internal@testing@@YAPAVTestInfo@2@PBD000PAXP6AXXZ2PAVTestFactoryBase@12@@Z)"
in Funktion ""void __cdecl `dynamic initializer for 'private: static
class testing::TestInfo * Test_One_Test::test_info_''(void)" (??__E?
test_info_@Test_One_Test@@0QAVTestInfo@testing@@A@@YAXXZ)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""protected: __thiscall testing::Test::Test(void)" (??
0Test@testing@@IAE@XZ)" in Funktion ""public: __thiscall
Test_One_Test::Test_One_Test(void)" (??0Test_One_Test@@QAE@XZ)".
googleTest.obj : error LNK2001: Nicht aufgelöstes externes Symbol
""protected: virtual void __thiscall testing::Test::SetUp(void)" (?
SetUp@Test@testing@@MAEXXZ)".
googleTest.obj : error LNK2001: Nicht aufgelöstes externes Symbol
""protected: virtual void __thiscall testing::Test::TearDown(void)" (?
TearDown@Test@testing@@MAEXXZ)".
googleTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol ""public: virtual __thiscall testing::Test::~Test(void)" (??
1Test@testing@@UAE@XZ)" in Funktion ""public: virtual __thiscall
Test_One_Test::~Test_One_Test(void)" (??1Test_One_Test@@UAE@XZ)".
C:\Dokumente und Einstellungen\Matthias Heppner\Eigene Dateien\Visual
Studio 2005\Projects\googleTest\Debug\googleTest.exe : fatal error
LNK1120: 13 nicht aufgelöste externe Verweise.
Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen
\Matthias Heppner\Eigene Dateien\Visual Studio 2005\Projects\googleTest
\googleTest\Debug\BuildLog.htm" gespeichert.
googleTest - 14 Fehler, 0 Warnung(en)

Vlad Losev

unread,
Oct 20, 2008, 1:45:51 PM10/20/08
to iiHeppa, Google C++ Testing Framework
Hi Matthias,

The errors are the linker errors. They indicate that the linker can't find symbols from gtest library. Most likely, the reason is you are not really linking with it. There are two ways to link against a library in Visual Studio. First an simpler one is to add gtest project to your solution and make it a dependency of your test (right click on your project, select "Add reference...", and then select gtest in Projects tab). Another way is to put gtest.lib as a library to link. This is done opening projects properties dialog and then in Configuration Properties/Linker/Input category, add the export library (gtest.lib file) path to the "Additional dependencies" field. Make that path relative to the test project directory.

Hope this helps.
Vlad
Reply all
Reply to author
Forward
0 new messages