gmock, gtest, ubuntu and C/C++
Sunday, March 29th, 2009There are a few projects that I have wanted to do for a very long time, some of which are products and some of which are tools. Over the weekend I thought I would use some very rare free time from looking after my twin son’s to look at using C/C++, google gtest and gmock to assess the “cost” to me of using them for one of these projects. I remember a time when testing in the C/C++ world was somewhat of a very manual task and one that didn’t get a lot of attention so I’m excited to be using gtest and gmock in with this language, but I’m not sure when my next free time is likely to be.
I downloaded gtest and followed the build instructions but the didn’t work but this may have just been my reading of the instructions, however, what follows are the steps I used to get gtest and gmock installed. What I have left to do now is create a C/C++ project and drive the first class forward with tests and mocks.
For Ubuntu 8.10 and gcc 4.3.2
- download gtest and unzip into a folder
- cd to that folder
- cd into the ’src’ folder
- make a ‘build’ folder
- cd into the ‘build’ folder
- run the command ‘../../configure
- run the command ‘make’
- run the command ‘make check’
- run ’sudo make install’ which will put the libraries, headers and executables in ‘/usr/local’
- add ‘/usr/local/lib’ to your LD_LIBRARY_PATH and optionally add ‘usr/local/bin’ to the PATH
- download gmock and unzip into a folder
- cd to that folder
- make a ‘build’ folder
- cd into the ‘build’ folder
- run the command ‘../configure CC=gcc-4 CXX=g++-4′
- run the command ‘make’
- run the command ‘make check’
- run ’sudo make install’ which will put the libraries, headers and executables in ‘/usr/local’
The above worked for me and all the tests ran (make check) without error. Note that I have added the ‘ CC=gcc-4 CXX=g++-4′ arguments to the configure step for gmock which are required in the latest cygwin release to ensure gcc version 4 is used. I don’t use these flags under linux and I don’t use them for gtest.
If you are wondering what it is I am building with C/C++, gtest and gmock then drop me an email or catch up with me at the next Melbourne Patterns group where I will be presenting.
