Question

I am migrating a project from Qt4 to Qt5. I finished migrating the project itself and now I am working on the libraries. So far I haven't had many problems converting and linking them to the project, but this one is throwing undefined references.

The project uses QtSerialPort, and it compiled perfectly using the Qt4 version of it, and it was linked like this in the .pro file:

-l:"C:/Users/Sprint/Desktop/swe/marssies/libQtSerialPort.a" \

I have compiled the Serial Port library with/for Qt5 and linked it as follows:

-l:"C:/Users/Sprint/Desktop/swe/marssies/libQt5SerialPort.a" \

But I keep getting these errors:

./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4ecc): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::availablePorts()'
Makefile.Release:922: recipe for target '..\Release\Swibz.exe' failed
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4f3e): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::portName() const'
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4f5d): 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
mingw32-make[1]: *** [..\Release\Swibz.exe] Error 1

I know its a linker error because of the "ld returned 1 exit status" I have tried linking the libQt5SerialPortd.a, libQt5SerialPort.dll and libQt5SerialPortd.dll but it throws the same errors
(By the way, if someone knows the difference between libNAMEd.a and libNAME.a please share your knowledge)

Maybe the QtAddOn is now in another library? Because otherwise it shouldnt recognize many other functions, not only the ones with QtAddOn.
Thankyou very much. I don't know what I would do without stackoverflow.

EDIT Alright, I found this which tells to change any SerialPortInfo declared variable to QSerialPortInfo, I have done that in my project and I am getting new errors, but now I am not sure which #include I should put:

#include <QtSerialPort>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QtSerialPort/QtSerialPort>

I have tried each one of these and all give me errors. Ill keep trying and see if anything comes clear

Was it helpful?

Solution

QtSerialPort is now a part of Qt. It officially became part of Qt with the 5.1.0 release. If you use the new version of Qt there is no need to get the source code separately and link to it.

To use the module with Qt 5 add this line to your qmake project file:

QT += serialport

You can then include the header files. To use these classes in your application, use the following include statement:

#include <QtSerialPort/QtSerialPort>

There is quite good documentation for the classes. You can view it from Qt Assistant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top