Debian does not provide any precompiled packages for gTest anymore. They suggest you to integrate the framework into your projects makefile. But I want to keep my make file clean. How do I setup gTest like the former versions (<1.6.0), so that I can link aganist the library?
相关问题
- How does the setup bootstrapper detect if prerequi
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
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.
1. Get the googletest framework
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.
2. Unpack and build google test
3. "Install" the headers and libs on your system.
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 supported4. Update the cache of the linker
... and check if the GNU Linker knows the libs
If the output looks like this:
, 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 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"
Just in case somebody else gets in the same situation like me yesterday (2016-06-22) and also does not succeed with the already posted approaches - on
Lubuntu 14.04
it worked for me using the following chain of commands:This will build and install both gtest and gmock 1.7.0:
This will install google test and mock library in Ubuntu/Debian based system:
Tested in google cloud in debian based image.
This answer from askubuntu is what worked for me. Seems simpler than other options an less error-prone, since it uses package
libgtest-dev
to get the sources and builds from there: https://askubuntu.com/questions/145887/why-no-library-files-installed-for-google-test?answertab=votes#tab-topPlease refer to that answer, but just as a shortcut I provide the steps here as well:
After that, I could build my project which depends on
gtest
with no issues.It took me a while to figure out this because the normal "make install" has been removed and I don't use cmake. Here is my experience to share. At work, I don't have root access on Linux, so I installed the Google test framework under my home directory:
~/usr/gtest/
.To install the package in ~/usr/gtest/ as shared libraries, together with sample build as well:
To validate the installation, use the following test.c as a simple test example:
To compile: