GTest and a few core ()

I have an Eclipse project. All test files are in a single * .cpp file. The problem is that this way I get two main functions (). One for the application itself and one for the test ones. And Eclipse, of course, refuses to build ... I would like to keep everything together within the same project (and avoid multiple configurations, SVN repositories, etc.). Ideally, I would like to force Eclipse to build two executables (one for the application and one for the test files). I quickly looked at Eclipse's Makefile, but to be honest, I don’t quite understand how it works. You can always exclude Main.cpp / Testcases.cpp and create one executable file, but it is not very elegant ...

Anyone with similar experience?

+4
source share
2 answers

Are you contacting libgtest_main in addition to libgtest? If you are not referencing libgtest_main, you should be good.

If you want to create two executables using the Eclipse CDT, the easiest way is for each executable to have a separate project. You can have a link to one project from another, if you have a common code.

+1
source

I came across this link which was very useful: http://pezad-games.googlecode.com/svn/trunk/GTestTest/HOWTO .

The author describes how to install gtest with one project in eclipse, having two source files with main() methods: one in the directory called "src" and the other in the directory called "test".

Therefore, he introduces a new configuration (besides DEBUG / RELEASE) called "GTEST" - in this configuration all links to the linker / header are set as gtest, as well as an exception for src / [main] .cpp:

Properties main.cpp -> C / C ++ Build -> Settings: exclude resource from assembly

On the other hand, the DEBUG and RELEASE configurations exclude the test / [main_test] .cpp.

+5
source

Source: https://habr.com/ru/post/1341028/


All Articles