使用 MSVC Express 的 qmake 中的标头依赖项
我在 Windows 上使用 QtCreator,使用 MSVC 编译器(来自 Visual c++ Express 版本的编译器)和 qt 4.5.2 开源。
当我修改项目上的标头并按 build all 时,实际上没有构建任何内容,只有当我修改 .cpp 文件时,才会编译修改后的 cpp。
这导致每次我必须更改多个 .cpp 文件使用的某些头文件时,我都必须重建一个完整的项目。 有办法避免这种行为吗?
提前致谢
I'm using QtCreator on windows using MSVC compiler (the compiler from Visual c++ express edition) and qt 4.5.2 open source.
When I modify a header on the project and press build all, nothing is actually built, only If I modify a .cpp file the modified cpp is compiled.
That causes that every time that I have to change some header file used by several .cpp files I have to rebuild a complete project. There is a way to avoid this behavior?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的头文件是否列在 .pro 文件的 HEADERS 变量中? 我认为在 HEADERS 中列出头文件也需要获取其中的类 MOC。
**[编辑]**没关系,我用 Linux 上的 Qt 4.5.2 SDK 中的 Qt Creator 1.2.1 对此进行了测试,当我“触摸”头文件时,它所依赖的 cpps 会重新编译,无论是否标头列在 HEADER 列表中。
在 qmake 生成的 Makefile 中,包含相关 h 文件的 cpp 文件有一条规则,明确将 h 文件列为依赖项。 不知道 qmake 是如何做到这一点的。 我建议查看为您生成的 makefile qmake,并查看其中一个 cpp 文件的规则是什么样的。[/edit]
[再次编辑,现在离开主题] **通常在调用 gcc 的基于 make 的构建系统中,您可以通过使用 -M 标志要求 gcc 为您生成 cpps 包含的头文件的依赖关系信息。 无论您要求多好,cl.exe(微软 C++ 编译器)都不会生成 .d 文件,因此通常使用它的 /showincludes 选项,然后使用脚本解析输出以将其转换为 .d 文件。 d 文件,这样 make 就可以包含它(很多人跳过这一步,只是在使用 cl.exe 的基于 make 的构建中没有适当的依赖项检查,因为它是一种 PITA)。 但是,我不认为 qmake 会做类似的事情来获取依赖信息,因为 qmake 正在生成一个 makefile,它反过来调用编译器,并且在那时,依赖信息(至少在我查看过的 makefile)是硬编码的。[/edit]**
Are your header files listed in the HEADERS variable in your .pro file? I think listing header files in HEADERS is also required to get classes within them MOC'ed.
**[edit]**Nevermind, I tested this out with Qt Creator 1.2.1 from the Qt 4.5.2 SDK on linux, and when I 'touch' a header file, the cpps it depends on are recompiled, whether or not the header is listed in the HEADER list.
In the Makefile qmake generates, my cpp files that include the h file in question have a rule that explicitly lists the h file as a dependancy. Not sure how qmake does that. I'd suggest looking in the makefile qmake generated for you, and seeing what the rule for one of your cpp files looks like.[/edit]
[edit again, getting off topic now]**Usually in make-based build system that invoke gcc, you generate dependency information for header files included by cpps by asking gcc to do it for you, with the -M flag. cl.exe (the microsoft C++ compiler) won't produce a .d file no matter how nicely you ask it, so it's somewhat common to use it's /showincludes option, and then parse the output with a script to convert it to a .d file so make can include it (a lot of people skip this step, and just don't have proper dependency checking in make-based builds that use cl.exe, because it's kind of a PITA). However, I don't think qmake does anything like that to get dependency information, because qmake is generating a makefile which in turn invokes the compiler, and at that point, the dependency info (at least in the makefile I looked at) is hard-coded.[/edit]**