1

I am migrating a huge project from Qt4.x to Qt5. Right now I am having this issue that I can't solve:

C:\Qt5\5.2.1\mingw48_32\lib/libQt5Core.a(d003170.o):(.text+0x0): multiple definition of `QString::fromUtf8(char const*, int)'
./release\aisinfowidget.o:aisinfowidget.cpp:(.text$_ZN7QString8fromUtf8EPKci[__ZN7QString8fromUtf8EPKci]+0x0): first defined here
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4dcc): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::availablePorts()'
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4e3e): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::portName() const'
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4e5d): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::description() const'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: ./release\gpssettingswidget.o: bad reloc address 0xd in section `.text$_ZN25Ui_GPSSettingsWidgetClass13retranslateUiEP14SettingsWidget[__ZN25Ui_GPSSettingsWidgetClass13retranslateUiEP14SettingsWidget]'
collect2.exe: error: ld returned 1 exit status
Victor
  • 907
  • 2
  • 17
  • 42
  • I saw `QtSerialPort` and `QextSerialPort`. Are you using them both? – Tay2510 Apr 30 '14 at 07:47
  • @Tay2510 Indeed, the project does use both. I know its not advisable but I cannot do anything about it. Whats on your mind? – Victor Apr 30 '14 at 07:47

1 Answers1

1

I saw you are using third party library QtSerialPort and QextSerialPort. Lucky you, I've been struggling with these two lovely guys these days.

The errors QString::fromUtf8 "possibly" come from the macro QStringLiteral defined in qserialportglobal.h

#ifndef QStringLiteral
#define QStringLiteral(str) QString::fromUtf8(str)
#endif

P.S. I am using Qt 4.8.5, there might be some difference.

In your gpssettingswidget.cpp, you don't have to include qserialportglobal.h again since it has been included in QSerialPort.

Remove the inclusion and see if it gets better, I know it's an arduous work to deal those multiple errors, and this answer definitely not the final remedy.

At least see what changes, and we can discuss here.


[Edit] I saw you are using Qwt too, I had a problem when using Qwt and QtSerialPort together. The question is here and has not yet been solved. I bypassed the conflict by migrating to QextSerialPort. There might be some library conflict, I doubt.

It seems that only Laszlo Papp can save your ass (He is one of the author of QtSerialPort)

Community
  • 1
  • 1
Tay2510
  • 5,748
  • 7
  • 39
  • 58
  • Thankyou for your answer, I have tried leaving only #include and still get the same errors. I even commented all of the qtserialports includes and the errors dont change, pretty strange if you ask me – Victor Apr 30 '14 at 08:03
  • Have you searched any new definition of `QString::fromUtf8` ? – Tay2510 Apr 30 '14 at 08:05
  • Indeed, and there are no new definitions in the project. Also I commented the linking to the library as well as the includes and still get the same errors. Maybe the lib im linking to is not the correct one? – Victor Apr 30 '14 at 08:08
  • Are you using `Qwt` too? – Tay2510 Apr 30 '14 at 08:12
  • He has saved my ass more than once in fact, I hope he does again. By the way, according to this http://qt-project.org/doc/qt-5/qtserialport-index.html I only need to add 'serialport' to the QT variable and do #include , but errors arent changing. I hope I dont have to migrate to QextSerialPort. Thankyou again. EDIT: Yes, the project uses Qwt too. – Victor Apr 30 '14 at 08:15
  • I suggest you open a new project and test if there is any conflict between 3rd party libraries (only do including things and linking libs, to see if it can be compiled). By the way, you haven't answered my question. Are you using `Qwt` ? (summon @Laszlo Papp here) – Tay2510 Apr 30 '14 at 08:19
  • I did answer it in my previous comment, I just edited it:P, yes, it does use qwt, as well as qtserialport and qextserialport, I know its crazy but theres nothing I can do about it (I am not the writter of the code, I am just the slave that has to do the tedious migrating) – Victor Apr 30 '14 at 08:21
  • @LaszloPapp I summon thee! – Victor Apr 30 '14 at 08:53
  • I'm using `QSerialPort` in my Qt5 project, but I don't have this error. – Siyuan Ren Apr 30 '14 at 09:11
  • Mixed `Qwt` and `QSerialPort`? – Tay2510 Apr 30 '14 at 09:12
  • @Tay2510 I managed to solve the errors, check out the main post – Victor Apr 30 '14 at 09:39
  • @VíctorAsdasd I'd like to know what've you dont to those files :) I didn't follow the sentence "have done the same for Qxmpp library" – Tay2510 Apr 30 '14 at 09:47
  • 1
    @Tay2510 For QtSerialPort I compiled the correct .pro file and got the correct library (There were so many .pro files that I didnt know which one to use, in fact I dont even remember which .pro file gave me the right lib) and then linked it. Then I did the same to the qxmmp.pro and got a libqxmpp.a file, (I was using libqxmpp_d.a that I got from another .pro file related to qxmpp), It has been a pretty messy task, I hope I made myself clear, please do ask if you dont understand something – Victor Apr 30 '14 at 09:58
  • Sounds very messy. So your diagnosis is that: you have been using broken libs which cause bad linking. Hmm... i'll keep following this issue. Thank you, and good luck! – Tay2510 Apr 30 '14 at 10:08