Why are changes in source not always reflected in machine code after build while rebuild works?(为什么在重建工作时构建后源代码的更改并不总是反映在机器代码中?)
问题描述
有时,当我更改 Qt 项目(带有 mingw32 的 Qt Creator 2.1.0)中的代码时,这些更改不会在构建后反映在生成的机器代码中.这主要发生在我更改构造函数中的默认值或方法/构造函数中的参数顺序等内容时.通常,完全重建可以解决这个问题(但需要几分钟时间).
Sometimes when I change code in my Qt project (Qt Creator 2.1.0 with mingw32), the changes don't get reflected in the produced machine code after building it. This happens mostly when I change things like default values in constructors or the order of parameters in methods/constructors. Usually, a full rebuild fixes that (but takes a few minutes).
我通过在构建之前删除生成的可执行文件或库来帮助自己,这似乎在大多数情况下都有帮助.这是否意味着链接目标文件时出现问题?
I'm helping myself by deleting the generated executables or librarys before building, which seems to help most of the time. Does that mean that theres something going wrong when linking the object files?
我来自 java/.net,我习惯了不同的行为.如果有人能解释我做错了什么和/或指出一些相关文章,我会很高兴.
I'm coming from java/.net and I'm used to a different behaviour. I'd be happy if anyone could explain me what I'm doing wrong and/or point me to some related articles.
谢谢!
推荐答案
通常,在标题更改后,应重建包括该标题在内的所有源文件.但是,qmake 在这方面有点奇怪,您需要为当前目录以外的包含文件夹设置 DEPENDPATH.例如,如果你有
Usually, after a change in a header, all source files including that header should be rebuilt. However, qmake is a bit peculiar in this regard, you need to set DEPENDPATH for include folders other than the current directory. E.g., if you have
INCLUDEPATH += somepath_in_my_project
也添加
DEPENDPATH += some_path_in_my_project
仅使用 DEPENDPATH,如果 some_path_in_my_project 中的某些标头发生更改(如果它们包含该标头),则由 .pro 文件构建的文件会重新构建!
Only with DEPENDPATH, files built by the .pro files are rebuilt if some header in some_path_in_my_project changes (if they include that header)!
我建议为每个 INCLUDEPATH 行添加一个相同的 DEPENDPATH 行,除非您包含一些您不希望更改的系统目录.
I suggest to add for each INCLUDEPATH line an identical DEPENDPATH line, unless you include some system directory you don't expect to change.
使用 qmake 静态链接时存在类似的问题:如果静态库 foo.a 更改,则不会重新链接与之链接的二进制文件.这是 QMake 中的一个错误,没有生成正确的依赖项.
A similar problem exists when linking statically with qmake: If the static lib foo.a changes, binaries linking against it are not relinked. That's a bug in QMake, not generating the correct dependencies.
我在以前的项目中找到的解决方法:
A workaround I found in a former project:
static:unix:TARGETDEPS += path_to_my/somestaticlib.a
static:win32:TARGETDEPS += path_to_my/somestaticlib.lib
编辑
从一段时间(Qt 5?)开始,上面的代码应该使用 POST_TARGETDEPS 而不是 TARGETDEPS.
Since some time (Qt 5?), above code should use POST_TARGETDEPS instead of TARGETDEPS.
这篇关于为什么在重建工作时构建后源代码的更改并不总是反映在机器代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么在重建工作时构建后源代码的更改并不总是反映在机器代码中?
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07