Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gTest and multiple main()

I have an Eclipse project. All testcases are in one *.cpp file. The problem is that this way I end up with two main() functions. One for the app itself and one for the testcases. And Eclipse, of course, refuses to build... I would like to keep everything together under one project (and avoid having multiple configurations, SVN repositories etc). Ideally, I would want to force Eclipse to build two executables (one for the app and one for the testcases). I had a quick look at the Eclipse Makefile, but to be honest, I don't quite understand how exactly it works. It is possible to always exclude Main.cpp/Testcases.cpp and build one executable, but it is not very elegant...

Anybody with similar experience?

like image 479
Petr Avatar asked Feb 23 '11 19:02

Petr


2 Answers

I stumbled over this link which was very helpfull: http://pezad-games.googlecode.com/svn/trunk/GTestTest/HOWTO.

The author is describing how to setup gtest with one project in eclipse whilst having two source files with main() methods: one in a directory called "src" and the other in a directory called "test".

Therefor he introduces a new configuration (besides DEBUG/RELEASE) called "GTEST" - in this configuration all linker/header includes are set to gtest and also an exclude to the src/[main].cpp:

Properties for main.cpp >> C/C++ Build >> Settings: Exclude resource from build

On the other side DEBUG & RELEASE configs exclude the test/[main_test].cpp.

like image 160
Del Pedro Avatar answered Oct 12 '22 17:10

Del Pedro


Are you linking with libgtest_main in addition to libgtest? If you don't link in the libgtest_main you should be good.

If you want to create two executables with Eclipse CDT the easiest way is to have each executable have a separate project. You can have one project reference another if you have common code.

like image 41
mikelong Avatar answered Oct 12 '22 16:10

mikelong