我正在尝试将我的 Qt 项目从 QMake 迁移到 CMake,但是在尝试使用 MSVC10 在 Windows 7 上构建我的库时遇到了一些错误。我的 CMakeLists.txt 文件如下:
cmake_minimum_required( VERSION 2.8.11 )
project( MyLibrary )
find_package(Qt4 REQUIRED)
set( CMAKE_AUTOMOC ON )
set( QT_USE_QTSCRIPT TRUE )
include( ${QT_USE_FILE} )
include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include ${QT_INCLUDES} )
set( MyLibrary_SOURCES
src/connection.cpp
src/mylibrary.cpp
src/node.cpp
src/socket.cpp
include/connection.h
include/mylibrary.h
include/node.h
include/socket.h
include/MyLibrary_global.h
)
add_library(MyLibrary SHARED ${MyLibrary_SOURCES})
target_link_libraries(MyLibrary ${QT_LIBRARIES} )
当我运行时,我尝试使用生成的 nmake Makefile 进行构建,但出现以下错误:
C2491:'Connection::staticMetaObjectExtraData' : definition of dllimport static data member not allowed
C2491: 'Connection::staticMetaObject' : definition of dllimport static data member not allowed
我是 CMake 的新手,所以我不确定我是否遗漏了 CMakeLists.txt 文件中的某些内容,或者是否有更多将它与 Qt 一起使用的技巧。我应该提一下,出现错误的文件是 MOC 生成的文件。
编辑:所以输出
消息(${QT_INCLUDES})
如下(格式化是为了便于阅读):
C:/Qt/4.8.3/include/QtDesigner
C:/Qt/4.8.3/include/QtDeclarative
C:/Qt/4.8.3/include/QtScriptTools
C:/Qt/4.8.3/include/QtDBus
C:/Qt/4.8.3/include/QtDesigner
C:/Qt/4.8.3/include/QtXml
C:/Qt/4.8.3/include/QtSql
C:/Qt/4.8.3/include/QtOpenGL
C:/Qt/4.8.3/include/QtMultimedia
C:/Qt/4.8.3/include/QtNetwork
C:/Qt/4.8.3/include/phonon
C:/Qt/4.8.3/include/QtXmlPatterns
C:/Qt/4.8.3/include/QtWebKit
C:/Qt/4.8.3/include/QtHelp
C:/Qt/4.8.3/include/QtUiTools
C:/Qt/4.8.3/include/QtTest
C:/Qt/4.8.3/include/QtScript
C:/Qt/4.8.3/include/QtSvg
C:/Qt/4.8.3/include/Qt3Support
C:/Qt/4.8.3/include/QtGui
C:/Qt/4.8.3/include/QtCore
C:/Qt/4.8.3/mkspecs/default
C:/Qt/4.8.3/include
C:/Qt/4.8.3/include/QtCore
我尝试不使用 auto-moc,但仍然得到相同的结果和错误。