Debian does not provide any precompiled packages for gTest anymore. They suggest you integrate the framework into your project's makefile. But I want to keep my makefile clean. How do I set up gTest like the former versions (<1.6.0), so that I can link against the library?
Go to Google test downloaded repo, extract it and navigate to: googletest →include →gtest [ex C:\Users\Downloads\googletest-release-1.10. 0\googletest-release-1.10. 0\googletest\include\gtest]. Copy that whole gtest file and copy to the folder MingW\lib\gcc\x86_64-w64-mingw32\8.1.
Before you start make sure your have read and understood this note from Google! This tutorial makes using gtest easy, but may introduce nasty bugs.
wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz
Or get it by hand. I won't maintain this little How-to, so if you stumbled upon it and the links are outdated, feel free to edit it.
tar xf release-1.8.0.tar.gz cd googletest-release-1.8.0 cmake -DBUILD_SHARED_LIBS=ON . make
This step might differ from distro to distro, so make sure you copy the headers and libs in the correct directory. I accomplished this by checking where Debians former gtest libs were located. But I'm sure there are better ways to do this. Note: make install
is dangerous and not supported
sudo cp -a googletest/include/gtest /usr/include sudo cp -a googlemock/gtest/libgtest_main.so googlemock/gtest/libgtest.so /usr/lib/
... and check if the GNU Linker knows the libs
sudo ldconfig -v | grep gtest
If the output looks like this:
libgtest.so.0 -> libgtest.so.0.0.0 libgtest_main.so.0 -> libgtest_main.so.0.0.0
then everything is fine.
gTestframework is now ready to use. Just don't forget to link your project against the library by setting -lgtest
as linker flag and optionally, if you did not write your own test mainroutine, the explicit -lgtest_main
flag.
From here on you might want to go to Googles documentation, and the old docs about the framework to learn how it works. Happy coding!
Edit: This works for OS X too! See "How to properly setup googleTest on OS X"
Let me answer this specifically for ubuntu users. First start by installing the gtest development package.
sudo apt-get install libgtest-dev
Note that this package only install source files. You have to compile the code yourself to create the necessary library files. These source files should be located at /usr/src/gtest. Browse to this folder and use cmake to compile the library:
sudo apt-get install cmake # install cmake cd /usr/src/gtest sudo mkdir build cd build sudo cmake .. sudo make sudo make install
Now to compile your programs that uses gtest, you have to link it with:
-lgtest -lgtest_main -lpthread
This worked perfectly for me on Ubuntu 14.04LTS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With