Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between gtest.lib and gtest_main.lib?

Google's C++ Test Framework has two output libraries: one is gtest.lib and the other one is gtest_main.lib. According to Nik Reiman's answer on how to setup gtest with Visual Studio, we should link to gtest_main.lib but I'm linking to gtest.lib and the sample test cases that I have are running fine.

What's the difference between the two libraries and does it matter which one I link to?

like image 931
Kiril Avatar asked Jun 23 '11 16:06

Kiril


People also ask

What is Gtest_main?

It includes a trivial main method that will launch the registered tests, something like this (as of 1.8): GTEST_API_ int main(int argc, char **argv) { printf("Running main() from gtest_main.cc\n"); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }

What is Gtest H?

h. The directory that contains gtest is not in your list of include search paths. gtest/gtest. h is working only because it's relative to the current file. You need to add the path that contains the directory gtest to your list of include search paths.


1 Answers

the only reasonable difference is that gtest_main.lib provides a default implementation of a test application entry point (i.e. main function):

Citation from Getting started with Google C++ Testing Framework:

"[...] maybe you think that writing all those main() functions is too much work? We agree with you completely and that's why Google Test provides a basic implementation of main(). If it fits your needs, then just link your test with gtest_main library and you are good to go."

If you want to write your main function yourself - you should link with gtest.lib.

like image 115
Andrey Avatar answered Oct 02 '22 13:10

Andrey