gTest 和多个 main()
我有一个 Eclipse 项目。所有测试用例都位于一个 *.cpp 文件中。问题是这样我最终得到了两个 main() 函数。一份用于应用程序本身,一份用于测试用例。当然,Eclipse 拒绝构建...我想将所有内容都放在一个项目下(并避免使用多个配置、SVN 存储库等)。理想情况下,我希望强制 Eclipse 构建两个可执行文件(一个用于应用程序,一个用于测试用例)。我快速浏览了 Eclipse Makefile,但说实话,我不太明白它到底是如何工作的。始终可以排除 Main.cpp/Testcases.cpp 并构建一个可执行文件,但这不是很优雅......
有人有类似的经验吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我偶然发现了这个非常有帮助的链接:http://pezad-games.googlecode .com/svn/trunk/GTestTest/HOWTO。
作者描述了如何在 Eclipse 中使用一个项目设置 gtest,同时拥有两个带有
main()
方法的源文件:一个位于名为“src”的目录中,另一个位于名为“test”的目录中。因此,他引入了一个名为“GTEST”的新配置(除了 DEBUG/RELEASE) - 在此配置中,所有链接器/标头包含都设置为 gtest,并且还排除 src/[main].cpp:
另一边 DEBUG & RELEASE 配置排除 test/[main_test].cpp。
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:
On the other side DEBUG & RELEASE configs exclude the test/[main_test].cpp.
除了 libgtest 之外,您还链接 libgtest_main 吗?如果你没有链接到 libgtest_main 你应该没问题。
如果您想使用 Eclipse CDT 创建两个可执行文件,最简单的方法是让每个可执行文件都有一个单独的项目。如果您有通用代码,则可以让一个项目引用另一个项目。
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.