use MinGW compile googletest on windows

enviornments

brief description of software installation

I wouldn’t write installation steps in detials, because there are many relaed article on the internet. It just some key points of I think.

MinGW installation

MinGW configuration
The figure shows my MinGW installation configuration and it looks work as well, I’m not sure other config information can work or not.

cmake installation

Cmake
Make sure you choose “Add Cmake to the system PATH for all users” or “Add Cmake to the system PATH for the current user”, otherwise, you need manually add the system PATH.

googletest

The project of googletest is on github.com, I believe you already have git bash software. We need to clone this project code from github. In a moment, we’ll use the git command.So we should use clone command instead of downloading directly.

git clone https://github.com/google/googletest.git

compile googletest

Firstly, you need enter the googletest folder and opening a git bash prompt windows . Running the following command in sequence.

git checkout release-1.10.0
cmake -G "MinGW Makefiles" -D CMAKE_C_COMPILER=gcc.exe ^
      -D CMAKE_CXX_COMPILER=g++.exe -DCMAKE_CXX_FLAGS=-std=c++11 ^
      -D CMAKE_MAKE_PROGRAM=mingw32-make.exe
make

now, if everything goes well, we can find lib/libgtest.a and ** lib/libgtest_main.a** in googletest direction.It is a very good info.
lib

attendion : git ckeckout release-1.7.0is necessery. I tired to compile with the main branch, but it failed.By querying related content, someone recommends using it.
main branch
Many arcticles indcatie suggest use cmake -G "MinGW Makefiles" -DCMAKE_CXX_FLAGS=-std=c++11,Unfortunately, I failed again.

a simple test

copy libgteat.a, libgteat_main.a and $(googletest)\include\gtest folder to project direction. New a test.cpp file.
code,

#include <iostream>
#include "gtest/gtest.h"

int foo()
{
    return 0;
}

TEST(FooTest, test)
{
    EXPECT_EQ(0, foo());
}

int main(int argc, char *argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

complie this project and run it,

g++ test.cpp  -L. -lgtest -lgtest_main -lpthread -I. -o test.exe
./test.exe

在这里插入图片描述
In this steps, I have a problem again. The pthread lib must be after gtest and gtest_main, I don’t know before and I didn’t pay attention to the order.I don’t know why, if you know, please leave a message and let me know.thank you very much.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值