Skip to content

Instantly share code, notes, and snippets.

@Cartexius
Last active November 7, 2024 00:57
Show Gist options
  • Save Cartexius/4c437c084d6e388288201aadf9c8cdd5 to your computer and use it in GitHub Desktop.
Save Cartexius/4c437c084d6e388288201aadf9c8cdd5 to your computer and use it in GitHub Desktop.
Install gtest in Ubuntu

Reference - https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/

sudo apt-get install libgtest-dev

sudo apt-get install cmake # install cmake

cd /usr/src/gtest

sudo cmake CMakeLists.txt

sudo make

sudo cp *.a /usr/lib

sudo ln -s /usr/lib/libgtest.a /usr/local/lib/gtest/libgtest.a

sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/gtest/libgtest_main.a

@dlime
Copy link

dlime commented Jan 31, 2020

I have no 'install' target by compiling /usr/src/gtest in ubuntu 19.04 (I did sudo apt-get install -y lgoogletest ibgtest-dev cmake)

@dlime
Copy link

dlime commented Jan 31, 2020

Hello guys, I've managed to install GTest & Gmock from the git repo:
https://gist.github.com/dlime/313f74fd23e4267c4a915086b84c7d3d

@georgegoldman
Copy link

so which is better approach ?

@georgegoldman
Copy link

what i got when i ran sudo cp libgtest* /usr/lib/
``
Uploading Screenshot from 2023-11-04 23-01-32.png…

@mamadrabiie
Copy link

mamadrabiie commented Nov 10, 2023

@georgegoldman I can't see the photo you uploaded, but I reckon your error relates to this:
Apparently, libgtest* files will be stored inside the lib directory so instead, you should run
sudo cp lib/libgtest* /usr/lib/

I combined all the answers above and minorly modified it, it worked on GitHub actions with -ubuntu-latest as well.

sudo apt-get install -y libgtest-dev cmake
mkdir -p $HOME/build
cd $HOME/build
sudo cmake /usr/src/googletest/googletest
sudo make
sudo cp lib/libgtest* /usr/lib/
cd ..
sudo rm -rf build
sudo mkdir /usr/local/lib/googletest
sudo ln -s /usr/lib/libgtest.a /usr/local/lib/googletest/libgtest.a
sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/googletest/libgtest_main.a

@kumailxp
Copy link

Thanks! Works like awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment