Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile googletest on windows using mingw with msys?

My need is simple. I have to compile and use googletest on windows using MinGW with msys. Has anyone some experience doing this?

Thanks for answers.

like image 254
Rusty Horse Avatar asked Mar 09 '11 15:03

Rusty Horse


2 Answers

From the README of https://github.com/google/googletest/tree/master/googletest : When building Google Test as a standalone project, the typical workflow starts with:

mkdir mybuild       # Create a directory to hold the build output.
cd mybuild
cmake ${GTEST_DIR}  # Generate native build scripts.

If you want to build Google Test's samples, you should replace the last command with

cmake -Dgtest_build_samples=ON ${GTEST_DIR}
like image 71
Lincoln Yesire Avatar answered Sep 18 '22 19:09

Lincoln Yesire


It took me some time but I figured it out. Here is the guide for anyone who face the same problem.

To be able to compile GoogleTest on Windows follow this instructions:

  1. I assume you have MinGW with MSYS istalled.

  2. Download and install CMake from the official site http://www.cmake.org/. Use the Win32 installer version. Once you have completed the installation process copy executable files from "xxx/CMake/bin" to "xxx/MinWG/bin".

  3. Download and install Python from http://www.python.org/. Again, the Windows installer does the job fine. Once you have completed the installation process copy the "python.exe" form python folder to "xxx/MinWG/bin".

  4. Download the latest stable GoogleTest from http://code.google.com/p/googletest/ and unpack it into some folder.

  5. Run MSYS terminal and execute following commands.

    cd xxx/gtest-x.x.x
    cmake -G "MSYS Makefiles"
    make
    
  6. If you have compilation errors from pthread follow these instructions.

  7. Copy the include folder "xxx/gtest-x.x.x/include" into your MinGW gcc include. Copy the library files "xxx/gtest-x.x.x/*.a" into your MinGW gcc lib.

  8. When you compile tests add "-lgtest" parameter to gcc.

EDIT Commentators are right. The coping of executables worked for me but generaly it is not a good practice. Try to use a symbolic link instead.

like image 25
Rusty Horse Avatar answered Sep 20 '22 19:09

Rusty Horse