如何在预构建中编译自动生成的 C 文件?
我有一个 Eclipse 项目,需要在编译之前自动生成一些文件。我不想将此自动生成的文件放入我的存储库中,因此每次编译项目时,我都会执行预构建以自动生成此文件。
问题是这个自动生成的文件是 *.c 和 *.h 文件,并且在我第一次编译项目时,会发生以下情况(按此顺序):
- 预构建:自动生成一些 *.c 和*.h
- build:eclipse不会构建这个自动生成的文件
如果我再次编译,这个文件将被编译。也许发生这种情况是因为 eclipse 将编译哪些文件的发现过程。在开始编译之前,我们没有自动生成的 *.c 和 *.h 文件。
在第二次编译时,我们已经有了这个自动生成的文件,因此这个文件被编译。
I have an Eclipse project that I need to auto-generate some files before compiling it. I do not want to put this auto-generated files in my repository, so each time I compile the projetct I perform a pre-build to auto-generate this files.
The problem is that this auto-generated files are *.c and *.h files, and in the first time I compile the project, the following happens (in this order):
- pre-build: auto-generate some *.c and *.h
- build: eclipse will not build this auto-generated files
If I compile again, this files will be compiled. Maybe this is happening because of the discovery process of what files eclipse will compile. Before initing compilation, we do not have this auto-generated *.c and *.h files.
In the second time we compile, we already have this auto-generated files, so this files are compiled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望完全控制自定义构建步骤何时发生、之后需要刷新哪些文件、环境、工作目录等。请勿将其指定为简单的预构建步骤。转到项目属性->建设者->新建...并选择“程序”。
在出现的对话框中,您可以更好地控制工具的执行。例如,您可以让工具在保存 XML 文件时运行,并且可以告诉 eclipse 在运行时刷新所有自动生成的文件。
If you want full control over when exactly the custom build step takes place, which files need to be refreshed after it, the environment, the working directory etc.. do not specify it as a simple pre-build step. Go to the project properties -> Builders -> New... and choose "Program".
In the resulting dialog, you have much more control over the execution of your tool. For instance, you can make your tool run whenever the XML file is saved, and you can tell eclipse to refresh all the auto-generated files whenever it is run.
如果我正确理解你的问题,似乎第一次构建项目会自动生成必要的 *.c 和 *.h 源文件,但项目将无法完全构建,因为无法立即找到这些源文件。经过短暂的延迟后,Eclipse 会识别出有新文件添加到项目中,然后您可以进行第二次构建,一切都会正常进行。听起来对吗?
假设是这种情况,我立即想到的是编写某种脚本或 makefile,以便所有这些操作都可以通过单个操作以正确的顺序发生。根据您想要弄脏的程度,这里有一个链接;)
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_makefile.htm
If I understand your question correctly, it seems that building your project the first time will auto-generate the necessary *.c and *.h source files, but the project will fail to fully build because these source files are not found immediately. After a small delay, Eclipse recognizes that there are new files added to the project and you can then build a second time and everything will proceed normally. Does that sound about right?
Assuming this is the case, my immediate thought is to write some sort of script or makefile so that all of these actions can take place in the proper order, with a single action. Depending on how dirty you want to get your hands, here's a link ;)
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_makefile.htm