You are not logged in.
Hello,
I have got a problem with Google test framework, few days ago I was trying this on another machine and did not get any problems.
I got this from svn and build libgtest.a. Then I tried to compile the first sample as:
g++ -I../include -L../ -lgtest -lpthread ../src/gtest_main.cc sample1.cc sample1_unittest.cc
But got a lot of linking errors like:
/tmp/ccVHpTQc.o: In function `main':
gtest_main.cc:(.text+0x28): undefined reference to `testing::InitGoogleTest(int*, char**)'
gtest_main.cc:(.text+0x2d): undefined reference to `testing::UnitTest::GetInstance()'
gtest_main.cc:(.text+0x35): undefined reference to `testing::UnitTest::Run()'
/tmp/ccQuonuE.o: In function `FactorialTest_Negative_Test::TestBody()':
sample1_unittest.cc:(.text+0x99): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xac): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xb8): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x15d): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x170): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x17c): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x221): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x234): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x240): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x271): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x2b4): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x2f9): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
As a workaround I unpack the library and got gtest-all.cc.o
ar x ../libgtest.a
So when I link samples with this object file - no errors:
g++ -I../include -L../ gtest-all.cc.o -lpthread ../src/gtest_main.cc sample1.cc sample1_unittest.cc
My g++ version is
[ds|samples]$ g++ --version
g++ (GCC) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
What can be wrong with my gcc?
Last edited by ds80 (2013-01-27 20:26:44)
Offline
The problem was fixed by changing ordering a litte - I just moved lgtest to the end:
g++ -I../include -L../ ../src/gtest_main.cc sample1.cc sample1_unittest.cc -lgtest -lpthread
Offline