Check google without DSO

I am studying the Google test. I downloaded gtest, executed the commands ./configure, makeand ended up with

$ sudo cp -a include/gtest /usr/include
$ sudo cp -a lib/.libs/* /usr/lib/

I got it all from here . I tried to run this code

#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();
}

like this

 $ export GTEST_HOME=~/usr/gtest
 $ export LD_LIBRARY_PATH=$GTEST_HOME/lib:$LD_LIBRARY_PATH
 $ g++ -I $GTEST_HOME/include -L $GTEST_HOME/lib -lgtest -lgtest_main -lpthread test.cpp

but i got an error

/usr/bin/ld: /tmp/ccVTj3Rk.o: undefined reference to symbol '_ZN7testing8internal9EqFailureEPKcS2_RKSsS4_b'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libgtest.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Am I doing something wrong or is it a mistake?

+4
source share
1 answer

There are some errors in your setup.

include/gtest /usr/include (sudo cp -a include/gtest /usr/include), , gtest ~/usr/gtest, , (/usr/include/gtest). lib/.libs/*. .

:

$ sudo cp -a include/gtest /usr/include
$ sudo cp -a lib/.libs/* /usr/lib/

#include <gtest/gtest.h> #include "gtest/gtest.h" :

g++ -g -Wall <your .cpp files> -I /usr/include/gtest/ -L /usr/lib/ -lgtest -lgtest_main -lpthread

. /a.out( , )

[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MathTest
[ RUN      ] MathTest.TwoPlusTwoEqualsFour
[       OK ] MathTest.TwoPlusTwoEqualsFour (0 ms)
[----------] 1 test from MathTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
+6

All Articles