2015-02-06 53 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