【问题标题】:CMake AutoMOC generates .cpp with errorsCMake AutoMOC 生成带有错误的 .cpp
【发布时间】:2017-10-26 16:26:46
【问题描述】:

我有一个通过 CMake 生成的项目,该项目也使用 AutoMOC 标志。但是,当我打开解决方案并尝试构建项目(使用 Visual Studio 15 2017 x64 生成器)时,这个特定项目会失败。我将在下面发布错误消息(有很多),但其中大多数是'struct'类型重新定义错误或由于多次初始化等导致的错误。不幸的是,因为大多数这些错误是在.cpp文件中找到的由 moc 自动生成,调试起来非常困难(或者一开始就知道它们为什么会发生)。

这是我的 CMakeList.txt

set(target QUI)

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5Widgets)
find_package(Qt5Network)
find_package(Qt5OpenGL)
find_package(Qt5PrintSupport)

if(WIN32)
    find_package(Qt5WinExtras)
endif()

set( headers
    # a bunch of headers here...
)

add_library(${target} "")

target_link_libraries(${target}
  PUBLIC Events Reflection DynamicDispatch Qt5::Widgets Qt5::Network Qt5::OpenGL Qt5::PrintSupport
  PRIVATE UI Net Registry
)

add_to_target( ${target} "${namespace}" "${headers}" "" )

generate_decl( ${target} "${namespace}" MLQ )

generate_ctags( ${tags_target} "${headers}" )

add_subdirectory( impl )

my_target_scope(${target})

然后这是我看到的错误的 sn-p。这个项目总共有大约 145 个错误。

错误

Error   C2011   'qt_meta_stringdata_MainWindow_t': 'struct' type redefinition (compiling source file C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\mocs_compilation.cpp)   C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\EWIEGA46WW\moc_MainWindow.cpp
Error   C2374   'qt_meta_stringdata_MainWindow': redefinition; multiple initialization (compiling source file C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\mocs_compilation.cpp)  C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\EWIEGA46WW\moc_MainWindow.cpp
Error   C2027   use of undefined type 'qt_meta_stringdata_MainWindow_t' (compiling source file C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\mocs_compilation.cpp) C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\EWIEGA46WW\moc_MainWindow.cpp
Error   C2227   left of '->stringdata0' must point to class/struct/union/generic type (compiling source file C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\mocs_compilation.cpp)   C:\GIT\src\Apps\MyApp\Qt\MyApp_autogen\EWIEGA46WW\moc_MainWindow.cpp    

【问题讨论】:

    标签: c++ qt cmake moc automoc


    【解决方案1】:

    因此,经过大量故障排除(并将一些文件与能够在其 Windows 机器上构建解决方案的同事进行比较)...我们能够确定问题归结为 CMake 如何处理 AutoMOC 过程。 .. 我相信他们在 CMake 版本 3.9 中进行了更改,导致了冲突 (see this thread)。显然,这已在 3.10 版中得到修复......一旦我更新到最新版本的 CMake,我的构建过程就会再次运行。希望这对将来的某人有所帮助。

    【讨论】:

      【解决方案2】:

      如果您使用的是 Windows,则此类问题的另一个原因可能是头文件和源文件之间的文件名大小写不同。如果你有“abc.cpp”和“Abc.h”,你最终会在moc-ed文件列表中得到一个重复的条目。 windows不区分大小写,但是moc系统可以...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-16
        • 1970-01-01
        • 2017-02-04
        • 1970-01-01
        • 2021-12-19
        • 2017-12-28
        相关资源
        最近更新 更多