我尝试编译我的项目之一,我的窗户由使用Qt5.3.1 MSVC2012,用现在Qt5.4 GCC 64位与Unbuntu 7 64位14.04 LTS。Qt的 - 未定义的参考...(Ubuntu的LTS 14.04 64位)
但我有一些“未定义的引用”错误:
/home/innocore/Software/CES_2015/trunk/MainProgram/../bin//libSmartphoneController.a(smartphonecontroller.o): In function
SmartphoneController::init()': /home/innocore/Software/CES_2015/trunk/bin/../LibSmartphoneController/smartphonecontroller.cpp:11: undefined reference to
RemoteADBInterface::RemoteADBInterface(QString, QString, int, QObject*)' /home/innocore/Software/CES_2015/trunk/bin/../LibSmartphoneController/smartphonecontroller.cpp:13: undefined reference toRemoteADBInterface::newMessage(RemoteADBInterface::Message const&, QVariant const&)' /home/innocore/Software/CES_2015/trunk/MainProgram/../bin//libSmartphoneController.a(smartphonecontroller.o): In function
QMetaObject::Connection QObject::connect(QtPrivate::FunctionPointer::Object const*, void (RemoteADBInterface::)(RemoteADBInterface::Message const&, QVariant const&), QtPrivate::FunctionPointer::Object const, void (SmartphoneController::*)(RemoteADBInterface::Message const&, QVariant const&), Qt::ConnectionType)': /opt/5.4/gcc_64/include/QtCore/qobject.h:239: undefined reference to `RemoteADBInterface::staticMetaObject' collect2: error: ld returned 1 exit status
我的项目是由一个EXE和几个库像libSmartphoneController.a或libRemoteADB.a的。
所有的库正确编译并在正确的目录中创建。当我编译我的exe程序(MainProgram)时,会出现问题。 在的.pro,我相信我有正确的依赖关系:
unix:!macx {
CONFIG(release, release|debug) {
LIBS += -L$$PWD/../Lib/ -lAudioPlayer -lDisplay -lSWCom -lRemoteADB -lDMS -lTVRemote \
-lHDMIMixer -lSmartphoneController -lRemoteServer
}
CONFIG(debug, release|debug) {
LIBS += -L$$PWD/../bin/ -lAudioPlayer -lDisplay -lSWCom -lRemoteADB -lDMS -lTVRemote \
-lHDMIMixer -lSmartphoneController -lRemoteServer
} }
的LIB SmartphoneController也有两个依赖:
在SmartphoneController.pro:
unix:!macx {
CONFIG(release, release|debug) {
LIBS += -L$$PWD/../Lib/ -lRemoteADB -lRemoteServer
}
CONFIG(debug, release|debug) {
LIBS += -L$$PWD/../bin/ -lRemoteADB -lRemoteServer
} }
的问题是它没有找到在lib RemoteADB一些功能(构造器,信号readMessage ...)的定义。我没有任何问题与所有其他库+它完美编译在windows ...
任何想法?
在此先感谢您的帮助
编辑:问题解决了感谢purplehuman。这是由于MainProgram的.pro文件中依赖项的顺序所致。
unix:!macx {
CONFIG(release, release|debug) {
LIBS += -L$$PWD/../Lib/ -lAudioPlayer -lDisplay -lSWCom -lDMS -lTVRemote \
-lHDMIMixer -lSmartphoneController -lRemoteServer -lRemoteADB
}
CONFIG(debug, release|debug) {
LIBS += -L$$PWD/../bin/ -lAudioPlayer -lDisplay -lSWCom -lDMS -lTVRemote \
-lHDMIMixer -lSmartphoneController -lRemoteServer -lRemoteADB #remoteADB has to be AFTER smartphonecontroller
} }
SmartphoneController取决于RemoteADB和REMOTESERVER,并MainProgram(主程序)取决于SmartphoneController的,所以在.pro文件,你必须把这个顺序的依赖关系:1)SmartphoneController 2)REMOTESERVER和RemoteADB
这是奇怪,这不是与Windows中的一个问题...
有时候顺序gcc中的库影响编译。我不知道这是否是这个问题,但只是你知道的。 – 2015-02-06 11:42:03
有趣的是,你如何强制另一个命令?我只需要改变.pro文件中的依赖顺序? – palador 2015-02-06 13:06:01
没错。我不确定这是否是问题,但过去我遇到过类似的问题,而改变顺序解决了问题。您可能需要在依赖关系之前添加依赖库。 – 2015-02-06 13:07:51