Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find -lgtest when setting up Google Test

Tags:

c++

googletest

I'm using Google Test for C++ and trying to set it up on my linux machine. My make file has the following code:

CC=g++ 
CFLAGS=-I $(GOOGLETESTDIR)/include -L $(GOOGLETESTDIR)/lib -lgtest -lpthread -Wall
DEPS=fib.h
OBJS=fib.o main.o

all: | r6

clean:
    -rm -f r6 $(OBJS)

%.o: %.cpp $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS) 

r6: $(OBJS)
    $(CC) -o $@ $^ $(CFLAGS) 
.PHONY: all clean

I get the error when I run make:

/usr/bin/ld: cannot find -lgtest

How do I fix this? I'm new to this kind of testing and rather new to linux so I'm really lost.

like image 735
user3339232 Avatar asked Mar 05 '15 03:03

user3339232


People also ask

How do I turn off test Google Test?

The docs for Google Test 1.7 suggest: If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).


1 Answers

I had this issue on Ubuntu 17.10 and basically what Alexander says is true.

Someone wrote a nice tutorial with explicit commands that can be found at https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/

It boils down to:

sudo apt install libgtest-dev cmake
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
sudo cp *.a /usr/lib

Personally, I would appreciate a solution that did not manually move files into /usr/lib, but on the plus side this works as-is.

like image 152
mnagel Avatar answered Oct 04 '22 10:10

mnagel