C++と色々

主にC++やプログラムに関する記事を投稿します。

MinGWのg++でgtestをビルドする

前提条件(私が成功した時の環境)

  • MinGWがインストールされていること
  • MinGWgcc, g++などがcmdにパスが通っていること
  • cmakeがインストールされていること、cmdにパスが通っていること
  • python2.7がインストールされていること、cmdにパスが通っていること

前提条件の確認

cmdの実行結果がだいたいイカのようになれば良いです。(細かいバージョンやパスは違っていても多分大丈夫だと思います)

c>where g++
C:\MinGW\bin\g++.exe

>g++ --version
g++ (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


>where python
C:\Python27\python.exe

>python --version
Python 2.7.10

>where cmake
C:\Program Files (x86)\CMake\bin\cmake.exe

>cmake --version
cmake version 3.3.0-rc3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

>

ビルド方法

この状態でgtestのzipを回答したフォルダへ移動し、そこにビルド用のフォルダを作成します。

>cd gtest-x.x.x
mkdir mybuild
cd mybuild

mybuildの中で

>cmake -G "MinGW Makefiles" ..

と実行します。成功すると以下の様なログを出力します

-- The CXX compiler identification is GNU 4.8.1
-- The C compiler identification is GNU 4.8.1
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: C:/Python27/python.exe (found version "2.7.10")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: mybuild

次にmybuildの中で、

>C:\MinGW\bin\mingw32-make

と実行します。mybuildの中にlibgtest.alibgtest_main.aができていれば成功です!

参考

llvm + clang + MinGW | lyuts.net 2014/11/03アクセス