On Ubuntu Linux, I have been following the gtest
instructions given here to install gtest
with manually copying the header files and libraries to /usr/include
and /usr/lib
, respectively.
I then tried to compile the following code (test1.cpp
)
#include <gtest/gtest.h>
TEST(MathTest, TwoPlusTwoEqualsFour) {
EXPECT_EQ(2 + 2, 4);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest( &argc, argv );
return RUN_ALL_TESTS();
}
with the following command (as suggested here and here)
g++ -Wall -g -pthread test1.cpp -lgtest_main -lgtest -lpthread
just to see the following errors:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libgtest.so: undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libgtest.so: undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libgtest.so: undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libgtest.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
The generic answer was about the order of the arguments to g++
. However, I think I have tried every combinatoric order of the arguments -lpthread
(with and without the l
), -lgtest
and -lgtest_main
. I always get the same errors.
I do not think the order is the problem. It must be something else. Anyone any ideas?