2015-02-06 96 views
1

我嘗試編譯我的項目之一,我的窗戶由使用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 to RemoteADBInterface::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中的一個問題...

+0

有時候順序gcc中的庫影響編譯。我不知道這是否是這個問題,但只是你知道的。 – 2015-02-06 11:42:03

+0

有趣的是,你如何強制另一個命令?我只需要改變.pro文件中的依賴順序? – palador 2015-02-06 13:06:01

+0

沒錯。我不確定這是否是問題,但過去我遇到過類似的問題,而改變順序解決了問題。您可能需要在依賴關係之前添加依賴庫。 – 2015-02-06 13:07:51

回答

0

我看到一個可能的原因您的問題:編譯器未找到庫文件,你可以通過在.pro文件中添加的完整路徑,你解決這個問題已經保存了這些庫,我在這裏可以看到的是你有不同的路徑去搜索h庫如果正在編譯調試或發佈,你確定在這兩個地方都有正確的庫嗎? 這將是放什麼在你的親文件的一個示例:

LIBS + = -L $$ OUT_PWD /../../../項目/ mylibs /發行/

+0

感謝您的回答,但我在同一目錄中有更多的庫,它看起來像libRemoteADB.a是導致此問題的唯一lib。其他人聯繫緊密。無論如何,我嘗試了完整的路徑和問題保持不變... – palador 2015-02-06 13:04:24

+0

在這種情況下,問題可能是在庫本身,看起來像你的libSmartphonecontroller已經建立使用不同版本的remoteADB和RemoteADBInterface :: newMessage (RemoteADBInterface :: Message const&,QVariant const&)'在RemoteADB llibrary中不再存在。 – Marco 2015-02-06 15:30:24

+0

實際上問題是MainProgram.pro文件中包含的依賴關係的順序(請參閱我的編輯)。所以現在就解決了:)! – palador 2015-02-06 15:52:03