QtDBus链接错误

时间:2013-01-10 12:34:50

标签: qt visual-c++ dbus unresolved-external qtdbus

我使用WinDBus在Windows上构建了Qt。 Qt本身构建正常,但QDbus示例构建失败并带有消息

moc_car_adaptor_p.obj : error LNK2001: unresolved external 
symbol "public: static struct QMetaObject const 
QDBusAbstractAdaptor::staticMetaObject"
(?staticMetaObject@QDBusAbstractAdaptor@@2UQMetaObject@@B)

文件夹E:\qt\4.6.4\msvc2008\lib包含QtDBus4.dll QtDBus4.lib QtDBusd4.dll和QtDBusd4.lib。全部包含'staticMetaObject@QDBusAbstractAdaptor@@2UQMetaObject@@B'字符串。

如何解决?

事先感谢,伊利亚。

UPD: 所有.PRO文件都来自DBus示例,我没有改变任何东西。例如:

######################################################################
# Automatically generated by qmake (2.01a) Mon Aug 28 19:50:14 2006
######################################################################

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += qdbus

# Input
# DBUS_ADAPTORS += car.xml
HEADERS += car.h car_adaptor_p.h
SOURCES += car.cpp main.cpp car_adaptor.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/car
sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xml
sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/car
INSTALLS += target sources

symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)

UPD2:

QtCreator生成的命令行:

... moc.exe and cl.exe calls...
cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189
-DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB
-DQT_THREAD_SUPPORT -I"..\..\..\..\msvc2008\include\QtCore" -I"..\..\..\..\msvc2008
\include\QtGui" -I"..\..\..\..\msvc2008\include" -I"..\..\..\..\msvc2008\include
\QtDBus" -I"..\car" -I"debug" -I"..\..\..\..\msvc2008\include\ActiveQt" -I"." 
-I"..\..\..\..\msvc2008\mkspecs\win32-msvc2008" 
-Fodebug\ @C:\DOCUME~1\resu\LOCALS~1\Temp\moc_car_adaptor_p.obj.432.2453.jom
moc_car_adaptor_p.cpp

link /LIBPATH:"e:\qt\4.6.4\msvc2008\lib" /NOLOGO /DEBUG /MANIFEST 
/MANIFESTFILE:"debug\car.intermediate.manifest" /SUBSYSTEM:WINDOWS 
/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' 
version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' 
processorArchitecture='*'" /OUT:debug\car.exe @C:\DOCUME~1\resu\LOCALS~1
\Temp\car.exe.432.3734.jom

我用Qt构建的选项:

configure.exe -platform win32-msvc2008 -shared  -debug-and-release -dbus -dbus-linked 
-qt-sql-sqlite -qt-sql-psql -no-qt3support -qt-zlib -qt-gif -qt-libpng -qt-libmng 
-qt-libtiff -qt-libjpeg -openssl-linked -confirm-license -opensource -phonon -phonon-
backend -nomake demos -nomake examples OPENSSL_LIBS="-lssleay32MD -llibeay32MD" 
-I "C:\OpenSSL-Win32\include" -I "C:\Progra~1\PostgreSQL\8.4\include" 
-I E:\qt\4.6.4\msvc2008\src\dbus" -I E:\qt\4.6.4\msvc2008\src\dbus\dbus" 
-L "C:\Progra~1\PostgreSQL\8.4\lib" -L "C:\OpenSSL-Win32\lib\VC\static" 
-l ws2_32 -l gdi32 -l user32 -l crypt32 -l advapi32

1 个答案:

答案 0 :(得分:1)

问题出在qdbusmacros.h

#if defined(QDBUS_MAKEDLL)
# define QDBUS_EXPORT Q_DECL_EXPORT
#elif defined(QT_SHARED)
# define QDBUS_EXPORT Q_DECL_IMPORT
#else
# define QDBUS_EXPORT
#endif

QT_SHARED未在申请中声明,QDBUS_EXPORT没有任何内容。

添加

CONFIG += QT_SHARED

解决了这个问题。

注意:在Qt 4.8.4中,一切正常(之前我使用的是4.6.4)