I want to run a unit test of a C++ class with gtest from with a command line under ubuntu x64. I was following a tutorial from a book, wich used the following command to to this:
g++ -o tester.exe MyClass1.cpp MyClass1Test.cpp
-I googletest/googletest -I googletest/googletest/include
-I googletest/googlemock -I googletest/googlemock/include
-I usr/lib/libgtest.a -l -lpthread
My 3 files look like this:
"MyClass1.cpp"
#include "MyClass1.h"
bool MyClass1::checkEquality(int number1, int number2) {
int result = number1 - number2;
if(result == 0) {
return true;
}
else {
return false;
}
}
int main() {}
"MyClass1.h"
class MyClass1 {
public:
bool checkEquality(int number1, int number2);
};
"MyClass1Test.cpp"
#include "MyClass1.h"
#include <gtest/gtest.h>
TEST ( MyClass1Test, checkIntEquality) {
MyClass1 myClass;
bool expectedResult = true;
int number1 = 10;
int number2 = 10;
bool result = myClass.checkEquality(number1, number2);
EXPECT_EQ(expectedResult, result);
}
I already tried playing around with the order of the parameters as suggested when I searched for an solution, but this did not give me a different output. I also read that the lpthread libary has something to do with this issue but I am unsure what to do about this.
The output I get from the command above is:
/tmp/ccJVQJv2.o: In function MyClass1Test_checkIntEquality_Test::TestBody()': MyClass1Test.cpp:(.text+0x72): undefined reference totesting::Message::Message()' MyClass1Test.cpp:(.text+0x9f): undefined reference to testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)' MyClass1Test.cpp:(.text+0xb2): undefined reference totesting::internal::AssertHelper::operator=(testing::Message const&) const' MyClass1Test.cpp:(.text+0xbe): undefined reference to testing::internal::AssertHelper::~AssertHelper()' MyClass1Test.cpp:(.text+0xe7): undefined reference totesting::internal::AssertHelper::~AssertHelper()' /tmp/ccJVQJv2.o: In function __static_initialization_and_destruction_0(int, int)': MyClass1Test.cpp:(.text+0x17b): undefined reference totesting::internal::GetTestTypeId()' MyClass1Test.cpp:(.text+0x1e9): undefined reference to testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)' /tmp/ccJVQJv2.o: In functionMyClass1Test_checkIntEquality_Test::MyClass1Test_checkIntEquality_Test()': MyClass1Test.cpp:(.text._ZN34MyClass1Test_checkIntEquality_TestC2Ev[_ZN34MyClass1Test_checkIntEquality_TestC5Ev]+0x14): undefined reference to testing::Test::Test()' /tmp/ccJVQJv2.o: In functiontesting::internal::scoped_ptr, std::allocator > >::reset(std::__cxx11::basic_string, std::allocator >)': MyClass1Test.cpp:(.text._ZN7testing8internal10scoped_ptrINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE5resetEPS7_[_ZN7testing8internal10scoped_ptrINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE5resetEPS7_]+0x24): undefined reference to testing::internal::IsTrue(bool)' /tmp/ccJVQJv2.o: In functiontesting::internal::scoped_ptr, std::allocator > >::reset(std::__cxx11::basic_stringstream, std::allocator >)': MyClass1Test.cpp:(.text._ZN7testing8internal10scoped_ptrINSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEEE5resetEPS7_[_ZN7testing8internal10scoped_ptrINSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEEE5resetEPS7_]+0x23): undefined reference to testing::internal::IsTrue(bool)' /tmp/ccJVQJv2.o: In functiontesting::AssertionResult testing::internal::CmpHelperEQ(char const*, char const*, bool const&, bool const&)': MyClass1Test.cpp:(.text._ZN7testing8internal11CmpHelperEQIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal11CmpHelperEQIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x36): undefined reference to testing::AssertionSuccess()' /tmp/ccJVQJv2.o: In functiontesting::AssertionResult testing::internal::CmpHelperEQFailure(char const*, char const*, bool const&, bool const&)': MyClass1Test.cpp:(.text._ZN7testing8internal18CmpHelperEQFailureIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal18CmpHelperEQFailureIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x6c): undefined reference to testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)' /tmp/ccJVQJv2.o:(.rodata._ZTV34MyClass1Test_checkIntEquality_Test[_ZTV34MyClass1Test_checkIntEquality_Test]+0x20): undefined reference totesting::Test::SetUp()' /tmp/ccJVQJv2.o:(.rodata._ZTV34MyClass1Test_checkIntEquality_Test[_ZTV34MyClass1Test_checkIntEquality_Test]+0x28): undefined reference to testing::Test::TearDown()' /tmp/ccJVQJv2.o: In functionMyClass1Test_checkIntEquality_Test::~MyClass1Test_checkIntEquality_Test()': MyClass1Test.cpp:(.text._ZN34MyClass1Test_checkIntEquality_TestD2Ev[_ZN34MyClass1Test_checkIntEquality_TestD5Ev]+0x20): undefined reference to testing::Test::~Test()' /tmp/ccJVQJv2.o:(.rodata._ZTI34MyClass1Test_checkIntEquality_Test[_ZTI34MyClass1Test_checkIntEquality_Test]+0x10): undefined reference totypeinfo for testing::Test' collect2: error: ld returned 1 exit status
Aucun commentaire:
Enregistrer un commentaire