开发者

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 und开发者_如何转开发erstand 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜