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
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.
Related
I am trying to write some code in C++ in QtCreator to connect to a grpc server when I get this compiler error:
/some/path/serverproxy.cpp:40: error: undefined reference to `grpc::InsecureChannelCredentials()'
Here's my grpc includes at the top of serverproxy.cpp
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
#include <grpc++/security/credentials.h>
and the error comes from this line:
somenamespace::NewStub(
grpc::CreateChannel("someaddress",
grpc::InsecureChannelCredentials()))};
I tried adding existing files and adding these headers in QtCreator (although it would be very strange to have to do that manually for the headers to all external libraries), but it didn't work. They are located at /usr/local/include/grpc++/**/*.h.
Also tried adding INCLUDEPATH += /usr/local/include to my .pro file.
I also tried cleaning the project, running qmake and building again.
What do I have to do to be able to use these grpc++ functions?
I looked at so many undefined reference in qtcreator threads without noticing this, which I finally saw here which is what got rid of the undefined reference errors:
You are facing a link error. Just add in your .pro the path to your
lib and its name with :
LIBS += -L<path_to_the_lib> -l<libName>
specifically
LIBS += -L/usr/local/include/grpc++ -lgrpc++
I have a very confusing (at least for me :) ) problem with linking to vtk-libraries. On one desktop pc, my code compiles without any error. I have an identical installation on another pc, but there, I get linker errors.
On both pc's are installed: itk 4.8, vtk 6.3 and cmake 3.3. Both are debian-systems (8.1 - jessie).
[ 96%] Linking CXX executable project
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit::~vtkRenderingVolume_AutoInit()':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit::~vtkRenderingVolumeOpenGL_ModuleInit()':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
libcommon.a(datareader.cpp.o): In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
collect2: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:326: recipe for target 'project' failed
I tried to fix those errors with adding
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
to the file where I am using the vtk libraries, but it didn't help.
Does anyone know what I'm doing wrong? I am wondering, why it works on one of those pcs but not on the other one.
thank you very much!
Update: I fixed my problem by switching the position of
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
in the CMakeLists to the end. However, does anyone know, why it makes such a huge difference for different pcs?
As long as the VTK_USE_FILE is found, your code should compile correctly. In your other PC, VTK_USE_FILE was already found from a previous configuration and sits in a CMake cache entry, so that is why it compiles fine.
If your are using Nightly,
Your should put these in front of your including any vtk headers.
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
and link all the library you made from vtk source
I'm trying to use SDL 2.0 in Qt Creator 3.1, using the Qt Build Suite (QBS) in Windows 7.
I've put the links in my .qbs to locate the SDL folders and I think everything works ok, because in my main.cpp it's recognizing the SDL functions, trying to autocomplete them.
The problem is, whenever I try to compile, I get the 'undefined reference to WinMain#16'
I'm using MinGW and set in the Compiler preferences the linker flags to: -lmingw32 -lSDL2main -lSDL2 -mwindows
The output is:
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/libmingw32.a(main.o): In function `main':
e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\bld/../mingwrt-4.0.3-1-mingw32-src/src/libcrt/crt/main.c:91: undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
And my .qbs is:
import qbs 1.0
CppApplication {
name: "testeSDL2"
cpp.includePaths: [".",
"C:/SDL2-2.0.3/i686-w64-mingw32/include"]
cpp.libraryPaths: [
"C:/SDL2-2.0.3/i686-w64-mingw32/lib"]
cpp.dynamicLibraries: "SDL2"
files: [
"main.cpp"
]
qbsSearchPaths: "C:/CppLibs/"
}
I've been searching a lot and only find answers for common Qt projects using the .pro but not the .qbs... And there's a section in the SDL site that says it's a linker problem, but I set them in the preferences window, my guess is that I also need to set them somehow in the .qbs file, but I don't have a clue on how to do so. Can anyone help?
As I recall, SDL defines a macro main that expands to some SDL-specific function name.
Find that macro definition and you also find the macro symbol you need to disable that thing.
Oh well maybe this should have been a comment not an answer, but when/if you find that (sorry I don't have time to check those sources) then you can mark this as “the solution”, he he. :-)
Addendum: since the OP kindly posted the SDL code, I've looked at it and found this comment:
“If you provide your own WinMain(), you may define SDL_MAIN_HANDLED”
… before including the SDL headers.
Then the macro called main is not defined.
So what I'm trying to do is stream an ip camera using phonon (vlc backend) in qt5.
I know phonon needs some changes in order to work in qt5 and I've made them, the libraries which used weren't writable, I made them writable, edited them but I'm still getting lots of errors.
Then I assumed there might be something wrong with phonon! so I downloaded phonon for qt 5. but the result was the same.
even creating an object gives me errors, after Googling my error, I found out there is linking problem but I don't know how to fix it.
.pro file:
Qt += phonon4qt5
header file:
#include <phonon4qt5/phonon/VideoPlayer>
.
.
.
Phonon::VideoPlayer *videoPlayer;
cpp file:
videoPlayer=new Phonon::VideoPlayer(Phonon::VideoCategory,this);
I get these errors:
/home/user/Projects/VideoPlayer-Phonon2/mainwindow.cpp:9: error: undefined reference to `Phonon::VideoPlayer::VideoPlayer(Phonon::Category, QWidget*)'
:-1: error: collect2: error: ld returned 1 exit status
Why are you struggling with Phonon? It's no longer supported in Qt5!
Anyway, undefined references means that you need to link the library explicitly. You have included with Qt += phonon4qt5, now you have to provide LIBS += -L/path/to/phonon -lphonon4qt5
I have a problem when using <boost/thread.hpp> in my code. When I try to compile it in Qt, I get these errors:
undefined reference to boost::system::generic_category()
undefined reference to boost::system::generic_category()
undefined reference to boost::system::system_category()
error: ld returned 1 exit status
Anyway, I searched StackOverflow and found this:
Undifined Reference With Boost When I Try To Compile
They say the key to solve this problem is adding -lboost_system. But where should I add this?? :( I'm a newbie in boost and Qt and I want don't wanna compile my programs using command-line directly. Is there a way to add these command-line options to Qt Creator?
I use Qt 5 with MinGW compiler and Boost 1.53. Thanks.
Add it to your .pro file:
LIBS += -L<their location> -lboost_system
I'm assuming that you have the boost_system library installed in a place the compiler will look of course.