How to Properly Setup Googletest on Os X Aside from Xcode

How to properly setup googleTest on OS X aside from XCode

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

$ wget https://github.com/google/googletest/archive/release-1.8.0.zip

Or get it by hand. I guess I won't manitain this little How-to, so if you stumbled upon it and the links are outdated, feel free to edit it.

2. Unzip and build google test

$ unzip gtest-1.8.0.zip
$ cd gtest-1.8.0
$ ./configure
$ make

3. "Install" the headers and libs on your system.

$ sudo cp -a include/gtest /usr/include
$ sudo cp -a lib/.libs/* /usr/lib/

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!

Issue installing GoogleTest on OS X (Sierra)

I just tried this on OS X; after the steps you listed, there's a subdirectory under build/ called googlemock/ containing libgmock.a and gtest/libgtest.a.

The headers are in the main folder under googletest/include/gtest/.

Alternatively, there's maybe some guidance in this older answer

Cant get gtest working with Xcode 6.2

I had the same issue and couldn't find out the problem.

Ended up installing the libraries and simply linking them to Xcode, as described in the answer here


I copy the instructions here too. The only difference is that I used /usr/local/include and /usr/local/lib

Moreover, do not forget to set these for your "Tests" target:

Library search paths:  /usr/local/lib
User header search paths: /usr/local/include
other linker flags: -lgtest

Copied:

1. Get the googletest framework

$ wget http://googletest.googlecode.com/files/gtest-1.7.0.zip

2. Unzip and build google test

$ unzip gtest-1.7.0.zip
$ cd gtest-1.7.0
$ ./configure
$ make

3. "Install" the headers and libs on your system.

$ sudo cp -a include/gtest /usr/include
$ sudo cp -a lib/.libs/* /usr/lib/

How to set up googleTest as a shared library on Linux

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

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.

2. Unpack and build google test

tar xf release-1.8.0.tar.gz
cd googletest-release-1.8.0
cmake -DBUILD_SHARED_LIBS=ON .
make

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.

sudo cp -a googletest/include/gtest /usr/include
sudo cp -a googlemock/gtest/libgtest_main.so googlemock/gtest/libgtest.so /usr/lib/

# The easiest/best way:
make install # Note: before v1.11 this can be dangerous and is not supported

4. Update the cache of the linker

... 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"

linking error when building Google test on mac (commandline)

Solution found. It turns out that the build instructions used are correct the issue was that on the computer that the build was being performed another developer had done some work with Google Test Framework 1.5 and they had installed the libraries on the computer in the compilers search path. This resulted in the compiler finding the other library first that was not compiled using multiple architecture options.

Issue installing GoogleTest on OS X (Sierra)

I just tried this on OS X; after the steps you listed, there's a subdirectory under build/ called googlemock/ containing libgmock.a and gtest/libgtest.a.

The headers are in the main folder under googletest/include/gtest/.

Alternatively, there's maybe some guidance in this older answer

Setup Google Test (gtest) with Eclipse on OS X

The -L switch only tells GCC a directory where to look for libraries, the actual library must be linked with -l:

g++ -L/usr/local/lib -lgtest ...


Related Topics



Leave a reply



Submit