包括在 Qt 项目上使用 CMake 和 Gnu 时出现的问题
我正在启动一个多平台(Win Xp、Linux)qt 项目。我想使用源代码构建,因此我的目录结构如下:
project/
CMakeLists.txt (global CMake file, includes other CMakeLists)
build/ (my build directory)
libA/
CMakeLists.txt
mystuff/
subprojectA/
CMakeLists.txt
subprojectB/
CMakeLists.txt
因此,当我在 Windows 上使用 Visual Studio 生成器时,一切都会构建得很好。 如果我在 Linux 上或在 Windows 下使用 MinGW 生成器使用相同的结构和 CMakeLists,我会收到编译错误,因为位于构建目录下的 qt 生成的文件(通过 moc 和 uic)无法在子项目中找到我的头文件。一些 qt 生成的头文件/源文件依赖于我的头文件/源文件,因为我在 .ui 文件中使用了提升的小部件,这些小部件指向我的源代码中的实现。再次在 Visual Studio / NMake 下一切都可以正常编译。
作为解决方法,我可以使用运行良好的源代码构建,或者我可以在全局 CMakeLists.txt 上添加以下内容:
include_directories(
mystuff/subprojectA
mystuff/subprojectB
)
但是什么是正确的解决方案?非常感谢!!
I am starting a multiplatform (Win Xp, Linux) qt project. I want to use an out of source build so my directory structure is as followed:
project/
CMakeLists.txt (global CMake file, includes other CMakeLists)
build/ (my build directory)
libA/
CMakeLists.txt
mystuff/
subprojectA/
CMakeLists.txt
subprojectB/
CMakeLists.txt
So when I use that on Windows with the Visual Studio generator everything builds fine.
If I use the same structure and CMakeLists on Linux or under Windows with the MinGW generator I get compile errors because the qt generated files (through moc and uic) lying under the build directory cannot find my header files in my subprojects. Some of the qt generated header/source files are dependent on my header/source files because I use promoted widgets in my .ui files which point to the implementation in my source. Again under Visual Studio / NMake everything compiles fine.
As a workaround I can use an in source build which runs fine or I can add the following on the global CMakeLists.txt:
include_directories(
mystuff/subprojectA
mystuff/subprojectB
)
But what is the right solution? Thank you very much!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个类似的问题,包含了 unix 上的源代码构建(尽管我没有使用 QT),并且在每个受影响的投影中我添加了:
不是最优雅的,但我为我工作。
I have a similar problem, with includes for out of source builds on unix (although I am not using QT), and in each effected projected I added:
Not the most elegant but I worked for me.
在我正在开发的项目中,我使用此语句来处理 CMakeLists.txt 中的包含内容:
关键字是 ${CMAKE_CURRENT_BINARY_DIR},希望有所帮助。
旁注,如果您使用启用了异常的 gcc 4.4.x,您可能需要使用它,这样它就不会链接到 Windows 上的 libgcc_s_sjlj-1.dll。
In a project I'm working on I use this statement to handle includes in my CMakeLists.txt :
The keyword is ${CMAKE_CURRENT_BINARY_DIR}, hope that helps.
Side note, if you are using gcc 4.4.x with exceptions enabled, you might want to use this so it wouldn't link against libgcc_s_sjlj-1.dll on windows.