包括在 Qt 项目上使用 CMake 和 Gnu 时出现的问题

发布于 2024-08-03 10:29:13 字数 774 浏览 7 评论 0原文

我正在启动一个多平台(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪淡了忧伤 2024-08-10 10:29:13

我有一个类似的问题,包含了 unix 上的源代码构建(尽管我没有使用 QT),并且在每个受影响的投影中我添加了:

include_directories( . )

不是最优雅的,但我为我工作。

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:

include_directories( . )

Not the most elegant but I worked for me.

只有影子陪我不离不弃 2024-08-10 10:29:13

在我正在开发的项目中,我使用此语句来处理 CMakeLists.txt 中的包含内容:

 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES} ${OPENSSL_INCLUDE_DIR})

关键字是 ${CMAKE_CURRENT_BINARY_DIR},希望有所帮助。

旁注,如果您使用启用了异常的 gcc 4.4.x,您可能需要使用它,这样它就不会链接到 Windows 上的 libgcc_s_sjlj-1.dll。

 SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static-libgcc")

In a project I'm working on I use this statement to handle includes in my CMakeLists.txt :

 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES} ${OPENSSL_INCLUDE_DIR})

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.

 SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static-libgcc")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文