0
votes

I try to include gtest to my C++ project. The IDE I'm using is CLion. I have this in my CMAKE

include_directories(/usr/local/include)
include_directories(/usr/local/lib)

and this in the file that I'm working on

#include "gtest/gtest.h"

I have installed gtest in the Terminal using these commands:

git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install

I'm assume that's enough to use gtest, but the Compiler says otherwise. This is the error message that I receive

ld: library not found for -lgtest
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone have an idea how I can fix it? Any attempt is appreciated!

Solution: I follow the direction on the README.md file from googletest github page and it works like a charm. https://github.com/google/googletest/blob/master/googletest/README.md

2
Investigate where make install installed it. - drescherjm
Welcome to Stack Overflow! Please provide the complete CMake file in your question post. This will help make the problem more clear so we can provide better solutions. - squareskittles
Hi @drescherjm, I'm pretty sure is in "/usr/local/include", I even try to copy the path from the file "/Users/myusername/googletest/googletest/include" - Vu Pham
Then check for the libraries at /usr/local/lib/ - drescherjm

2 Answers

0
votes

Usually gtest is a static library, so you need to specify libgtest.a, something like this:

g++ -std=c++17 -O3 -pedantic-errors test.cpp /usr/lib/libgtest.a -o test
0
votes

I follow the direction on the README.md file from googletest github page and it works like a charm. https://github.com/google/googletest/blob/master/googletest/README.md