【发布时间】: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
【问题讨论】: