How to configure googleTest on OS X aside from Xcode

How to configure gTest to associate an agent with a library? I will code in vim, so I just want to install the libraries, unlike the Xcode setup . The goal is to be able to link the project to the library by setting -lgtest as the linker flag and, if desired, if I did not write my own mainroutine tag, the explicit -lgtest_main flag.

+11
c ++ googletest macos
Dec 23 '13 at 15:12
source share
3 answers

Before you begin, make sure you read and understand this post from Google ! This tutorial makes using gtest easy, but may contain unpleasant errors .

1. Get googletest frame

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

Or get his hand . I think I won’t beckon this little How-to, so if you come across it and the links are out of date, feel free to edit it.

2. Unzip and create a Google test

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

3. β€œInstall” headers and libraries on your system.

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

gTestframework is now ready for use. Just remember to link your project to the library by setting -lgtest as the linker flag and, if necessary, if you have not created your own test mainroutine, the explicit flag -lgtest_main .

Here you can go to the Googles documentation about the structure to find out how it works. Happy coding!

+13
Jan 10
source share

He advises you to statically set the link. There are no secrets. Being a bit offtopic, I use CMake in my projects, which I recommend, and here ( https://github.com/oblitum/operations ) I have a very simple skeletal project that references gmock and gtest (it also advises google that you use the same gtest from gmock when you use gmock). The external folder contains external CMake files that actually import gtest and gmock through ExternalProject_Add . In the sample, I set the URL as the file path on my system where gmock and gtest are loaded, but if you check the CMake ExternalProject_Add docs, you will see that the downloadable URLs are also available online repository, which allows your assembly to download gtest and gmock and cache it automatically.

+2
Dec 24 '13 at 6:15
source share

I think cmake is an easy way to configure and use gtest on OSX. It works without manually copying files. Unzip gooletest-release-1.8.0 , then

 cd googletest-release-1.8.0 # create a build directory mkdir build cd build # build configuration cmake .. -DBUILD_GTEST=ON -DBUILD_SHARED_LIBS=ON # build it make # installation sudo make install 

Subsequently, you can easily include gtest in your project using cmake commands

 # sets GTEST_INCLUDE_DIRS and GTEST_LIBRARIES find_package( GTest REQUIRED ) # adds the gtest include directory include_directories( ${GTEST_INCLUDE_DIRS} ) # links gtest target_link_libraries( yourTestApp ${GTEST_LIBRARIES} ) 
0
Feb 02 '18 at 10:51
source share



All Articles