Eclipse CDT:如何在单个 C++ 项目中管理多个 main() 函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19789104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse CDT : How to manage multiple main() functions in a single C++ project?
提问by feronjb
I am starting the developpement of a project which will be made of multiple modules. I will validate each of those modules with a dedicated testbench, each with their main() function.
I would like to avoid having one Eclipse project for each testbench and its main() function.
我正在开始开发一个由多个模块组成的项目。我将使用专用的测试平台验证每个模块,每个模块都有它们的 main() 函数。
我想避免为每个测试平台及其 main() 函数创建一个 Eclipse 项目。
I read about Working Setsand the idea of showing only the files concerned for a particular testbench in my project is what I search for.
我阅读了有关工作集的内容,并且只显示与我的项目中特定测试平台相关的文件的想法是我搜索的内容。
However, during the build phase, Eclipse continues building all the project files, not the current Working Set files only. I then have a Linker error because of multiple main() functions.
但是,在构建阶段,Eclipse 会继续构建所有项目文件,而不仅仅是当前的工作集文件。由于多个 main() 函数,我然后有一个链接器错误。
How can I configure Eclipse to Build the files of a Working Set only?
Is there another way to build multiple programs separately in a single project, i.e. an application and its components testbenches?
如何配置 Eclipse 以仅构建工作集的文件?
是否有另一种方法可以在单个项目中单独构建多个程序,即应用程序及其组件测试平台?
采纳答案by feronjb
It is possible to deal with multiple main functions in Eclipse CDT by writting a custom makefile. It is a potential solution for C/C++ projects dealing with a main application and its components testbenches, for instance.
可以通过编写自定义的makefile来处理 Eclipse CDT 中的多个主要功能。例如,它是处理主要应用程序及其组件测试平台的 C/C++ 项目的潜在解决方案。
See herehow to specify a custom makefile in Eclipse.
Then, define a main rule (see makefiledocumentation) building your whole application (without the testbenches) and define one additional rule for each of your testbenches (with its component) to be built.
To summarize : define one rule in your makefile for each of your main function, building the main and its dependencies.
请参阅此处如何在 Eclipse 中指定自定义 makefile。
然后,定义构建整个应用程序(没有测试平台)的主要规则(请参阅makefile文档),并为要构建的每个测试平台(及其组件)定义一个附加规则。
总结一下:在你的 makefile 中为每个 main 函数定义一个规则,构建 main 及其依赖项。