1

I try to compile one of my project I made with windows 7 64 bits using Qt5.3.1 MSVC2012, by using now Qt5.4 gcc 64 bits with Unbuntu 14.04 LTS.

But I have some "undefined reference to" errors :

/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 toRemoteADBInterface::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 functionQMetaObject::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

my project is composed of one exe and several libraries like libSmartphoneController.a or libRemoteADB.a.

All the libraries compile correctly and are created in the right directory. The problem occurs when I compile my exe program (MainProgram). In the .pro, I'm sure I include the right dependencies :

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
} }

The lib SmartphoneController also have two dependencies :

in SmartphoneController.pro :

unix:!macx {
CONFIG(release, release|debug) {
LIBS += -L$$PWD/../Lib/ -lRemoteADB -lRemoteServer
}
CONFIG(debug, release|debug) {
LIBS += -L$$PWD/../bin/ -lRemoteADB -lRemoteServer
} }

The problem is that it does not find the definition of some function in the lib RemoteADB (contructor, signal readMessage...). I don't have any problem with all other libs + it compiles perfectly on windows...

Any idea ?

Thanks in advance for your help

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
palador
  • 273
  • 2
  • 3
  • 11
  • Sometimes the order of libraries in gcc affects the compilation. I don't know if this is the problem here, but just so you know. –  Feb 06 '15 at 11:42
  • Interesting, how can you force another order ? I just have to change the dependency order in .pro files ? – palador Feb 06 '15 at 13:06
  • That's right. I'm not sure that's the problem here, but in the past I had some similar problems, and changing the order solved it. You might need to add the dependant libraries before dependencies. –  Feb 06 '15 at 13:07
  • Well the problem was actually something like that ! I had to put the "sub-dependant" lib AFTER the dependent lib in the mainProgram.pro file. I'm goint to edit my question to show you. Thanks a lot ! – palador Feb 06 '15 at 14:24
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – sashoalm Feb 06 '15 at 14:29
  • You're right. "Common causes include: The order in which interdependent linked libraries are specified is wrong" – palador Feb 06 '15 at 14:36

1 Answers1

0

I see a possible cause for your problem: the compiler does not find the library file and you can solve this by adding in the .pro file the full path where you have saved the libraries, what I can see here is that you have different path where to search libraries if are compiling debug or release, are you sure you have the correct libraries in both places ? This would be an example of what to put in your pro file:

LIBS += -L$$OUT_PWD/../../../projects/mylibs/release/

Marco
  • 1,952
  • 1
  • 17
  • 23
  • Thanks for your answer, but I have more libraries in the same directory and it looks like libRemoteADB.a is the only lib that causes this problem. The others are well linked. Anyway I tried with the full path and the problem remained the same... – palador Feb 06 '15 at 13:04
  • In that case the problem is probably in the library itself, looks like the libSmartphonecontroller you have has been build using a different version of remoteADB and the RemoteADBInterface::newMessage(RemoteADBInterface::Message const&, QVariant const&)' is not present anymore in the RemoteADB llibrary. – Marco Feb 06 '15 at 15:30
  • Actually the problem was the order of dependencies included in the MainProgram.pro file (see my edit). So it's solved now :) ! – palador Feb 06 '15 at 15:52