标签:use git windows MinGW compile gtest googletest test main
table of contents
enviornments
- windows 10
- MinGW-w64
- CMake 3.22.1
- googletest
brief description of software installation
I‘ll not write installation steps in detials, because there are many relaed article on the internet. It just some key points of I think.
MinGW installation
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
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, enter the googletest direction and open a git bash prompt windows, Run the following command in sequence.
git checkout release-1.7.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 libgtest.a and ** libgtest_main.a** in googletest direction.It is a very good info.
attendion : git ckeckout release-1.7.0
is necessery. I tired to compile with the main branch, but it failed.By querying related content, someone recommends using it.
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.
标签:use,git,windows,MinGW,compile,gtest,googletest,test,main 来源: https://blog.csdn.net/main_h_/article/details/121675563
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。