-
Notifications
You must be signed in to change notification settings - Fork 3
Compiling GTest
Compiling GTest is quite a bit of work on any operating system. Find the appropriate one for you and make sure to follow the directions to a T.
Compiling GTest on OS X is a huge pain. These instructions explain how to compile it using Xcode.
- First download GTest-1.6.0
- Unzip the archive to $GTEST_HOME
- A good example of $GTEST_HOME is /Users/username/Programming/Libraries/gtest-1.6.0-src
- Open $GTEST_HOME/xcode/gtest.xcodeproj
- Select the gtest project
- Under Build Settings, make sure you have the 10.8 Base SDK selected
- Under Build Settings, make sure you have the Apple LLVM compiler 4.1 selected
- Select the gtest-framework target
- Under Build Settings, make sure you have the "Symbols Hidden by Default" set to "No" (removes visibility errors when compiling the Bump unittests)
- Select the gtest-static target
- Under Build Settings, make sure you have the "Symbols Hidden by Default" set to "No"
- Select the gtest_main-static target
- Under Build Settings, make sure you have the "Symbols Hidden by Default" set to "No"
- Select the Check target in the top-left dropdown to build
- Edit the scheme to build in Release
- Build the target (the samples and tests fail, but the framework and libraries succeed)
- Open a Finder window
- cd to ~/Library/Developer/Xcode/DerivedData/gtest-*/Build/Products/Release
- Copy the static libs to $INSTALL_HOME/lib
- A good example of $GTEST_HOME is /Users/username/Programming/Libraries/gtest-1.6.0
- Edit the scheme to build in Debug
- Build the target (the samples and tests fail, but the framework and libraries succeed)
- Open a Finder window
- cd to ~/Library/Developer/Xcode/DerivedData/gtest-*/Build/Products/Debug
- Rename the gtest-static.a to gtest-staticd.a and the gtest_main-static.a to gtest_main-staticd.a
- Copy the Debug static libs to $INSTALL_HOME/lib
- Copy the $GTEST_HOME/include directory to $INSTALL_HOME/include
As you can see, this methods uses the static gtest libs and not the framework. If you want to use the framework, then you'll have to figure it out on your own :-(
Compiling GTest in Visual Studio isn't too bad. You want to use CMake to make it the easiest. The hardest decision is really whether to build static or shared libs.
- First download GTest-1.6.0
- Unzip the archive to $GTEST_HOME
- A good example of $GTEST_HOME is C:\libraries\gtest-1.6.0-src
- Launch CMake (cmake-gui)
- Set the "Where is the source code:" to $GTEST_HOME
- Set the "Where to build the binaries:" to $GTEST_HOME\build.win32
- Hit the Configure button
- Select "Visual Studio 2008 9" and native default compilers
- Check both the Grouped and Advanced options
- Under Ungrouped Entries:
- BUILD_SHARED_LIBS - Unchecked
- Under CMake:
- CMAKE_CONFIGURATION_TYPES - Debug;Release
- CMAKE_INSTALL_PREFIX - $INSTALL_HOME (C:\libraries\gtest-1.6.0)
- Under gtest:
- gtest_build_samples - Unchecked
- gtest_build_tests - Unchecked
- gtest_disable_pthreads - Unchecked
- gtest_force_shared_crt - Checked
- Hit the Configure button again (keep hitting under all red goes away)
- Hit the Generate button
- Go the the directory $GTEST_HOME\build.win32
- Open the ALL_BUILD.vcproj with Visual Studio
- Set the build type to Debug
- Right click on the ALL_BUILD project and select Build
- Set the build type to Release
- Right click on the ALL_BUILD project and select Build
- Go to the $GTEST_HOME\build.win32\Debug folder
- Delete everything except the *.lib and *.pdb files
- Add a "d" to the end of all the files
- Create the $INSTALL_HOME\lib directory
- Copy all the $GTEST_HOME\build.win32\Debug*.lib and *.pdb files to $INSTALL_HOME\lib
- Go to the $GTEST_HOME\build.win32\Release folder
- Delete everything except the *.lib files
- Copy all the $GTEST_HOME\build.win32\Debug*.lib files to $INSTALL_HOME\lib
- Copy the $GTEST_HOME\include folder to $INSTALL_HOME\include
- First download GTest-1.6.0
- Unzip the archive to $GTEST_HOME
- A good example of $GTEST_HOME is C:\libraries\gtest-1.6.0-src
- Launch CMake (cmake-gui)
- Set the "Where is the source code:" to $GTEST_HOME
- Set the "Where to build the binaries:" to $GTEST_HOME\build.win32
- Hit the Configure button
- Select "Visual Studio 2008 9" and native default compilers
- Check both the Grouped and Advanced options
- Under Ungrouped Entries:
- BUILD_SHARED_LIBS - Checked
- Under CMake:
- CMAKE_CONFIGURATION_TYPES - Debug;Release
- CMAKE_INSTALL_PREFIX - $INSTALL_HOME (C:\libraries\gtest-1.6.0)
- Under gtest:
- Uncheck everything
- Hit the Configure button again (keep hitting under all red goes away)
- Hit the Generate button
- Go the the directory $GTEST_HOME\build.win32
- Open the ALL_BUILD.vcproj with Visual Studio
- Set the build type to Debug
- Right click on the ALL_BUILD project and select Build
- Set the build type to Release
- Right click on the ALL_BUILD project and select Build
- Go to the $GTEST_HOME\build.win32\Debug folder
- Delete everything except the *.dll, *.lib and *.pdb files
- Add a "d" to the end of all the files
- Create the $INSTALL_HOME\lib and $INSTALL_HOME\bin directories
- Copy all the $GTEST_HOME\build.win32\Debug*.dll files to $INSTALL_HOME\bin
- Copy all the $GTEST_HOME\build.win32\Debug*.lib and *.pdb files to $INSTALL_HOME\lib
- Go to the $GTEST_HOME\build.win32\Release folder
- Delete everything except the *.dll and *.lib files
- Copy all the $GTEST_HOME\build.win32\Debug*.dll files to $INSTALL_HOME\bin
- Copy all the $GTEST_HOME\build.win32\Debug*.lib files to $INSTALL_HOME\lib
- Copy the $GTEST_HOME\include folder to $INSTALL_HOME\include
- Add the $INSTALL_HOME\bin to the $PATH environment variable to pick up the dlls at runtime
It doesn't matter whether you use static or shared GTest libraries...totally your preference. I personally prefer to use static libraries to avoid having to set the $PATH environment variable. Plus it's just easier....less files to deal with.
Compiling GTest on linux isn't bad. You want to use CMake to make it the easiest.
- First download GTest-1.6.0
- Unzip the archive to $GTEST_HOME
- A good example of $GTEST_HOME is /home/username/Programming/Libraries/gtest-1.6.0-src
- Launch CMake (cmake-gui)
- Set the "Where is the source code:" to $GTEST_HOME
- Set the "Where to build the binaries:" to $GTEST_HOME/build.linux64
- Hit the Configure button
- Select "Unix Makefiles" and native default compilers
- Check both the Grouped and Advanced options
- Under Ungrouped Entries:
- BUILD_SHARED_LIBS - Unchecked
- Under CMake:
- CMAKE_CONFIGURATION_TYPES - Debug
- Under gtest:
- gtest_build_samples - Unchecked
- gtest_build_tests - Unchecked
- gtest_disable_pthreads - Unchecked
- gtest_force_shared_crt - Checked
- Hit the Configure button again (keep hitting under all red goes away)
- Hit the Generate button
- Go to the directory $GTEST_HOME/build.linux64
- Type "make -j 8"
- Rename libgtest.a to libgtestd.a
- Rename libgtest_main.a to libgtest_maind.a
- Create the $INSTALL_HOME/lib directory
- A good example of $INSTALL_HOME is /home/username/Programming/Libraries/gtest-1.6.0
- Copy libgtestd.a and libgtest_maind.a to $INSTALL_HOME/lib
- Launch CMake (cmake-gui)
- Under CMake:
- CMAKE_CONFIGURATION_TYPES - Release
- Hit the Configure button again (keep hitting under all red goes away)
- Hit the Generate button
- Go to the directory $GTEST_HOME/build.linux64
- Type "make -j 8"
- Copy libgtest.a and libgtest_main.a to $INSTALL_HOME/lib
- Copy the $GTEST_HOME/include folder to $INSTALL_HOME/include
It doesn't matter whether you use static or shared GTest libraries...totally your preference. If you want to use shared libraries, then slightly alter the CMake settings and make sure to set your LD_LIBRARY_PATH environment variable. I personally prefer to use static libraries to avoid having to set more environment variables.