Qt/C++ linkage error (undefined reference) - c++

I have troubles when I'm trying to make a linkage with static C/C++ library. Using QtCreator 2.7.2/Qt4.8/RHEL6. Here .pro file:
QT += core gui widgets
DESTDIR = ../bin
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
LIBS += -L$$PWD/../bin/ -lsip
INCLUDEPATH += $$PWD/../sip/include
TARGET = sipgui
TEMPLATE = app
SOURCES += main.cpp\
....
HEADERS += \
connectionpool.h \
....
FORMS += dialog.ui
unix|win32: LIBS += -lcurses
When I'm calling library method from my project, i get "undefined reference" compilation error:
thread.o: In function `print_last_stats':
/home/virtual/Project/sip/build-sipgui-Desktop-Debug/../sipgui/thread.cpp:61: undefined reference to `print_statistics'
....
/home/virtual/Project/sip/build-sipgui-Desktop-Debug/../sipgui/thread.cpp:64: undefined reference to `print_statistics'
/home/virtual/Project/sip/sipgui/../bin//libsip.a(sipp-scenario.o): In function `scenario::parseAction(CActions*)':
/home/virtual/Desktop/sipp-3.4.1/sipp-3.4.1/src/scenario.cpp:1627: undefined reference to `hasMedia'
So, what am I doing wrong?

Related

How can I use libraw in QT?

I have installed LibRaw-0.20.1.zip from https://www.libraw.org/download.
I compile it, and produce libraw.lib and libraw.dll. It is 32 bit.
I then use it in qt:
win32: LIBS += -L$$PWD/../../LibRaw-0.20.0/lib/ -llibraw
INCLUDEPATH += $$PWD/../../LibRaw-0.20.0
DEPENDPATH += $$PWD/../../LibRaw-0.20.0
This path is right, but I get this is error:
C:\QtProject\UDP\mainwindow.cpp:359: error: undefined reference to `LibRaw::LibRaw(unsigned int)'

undefined reference in Qt creator for DCMTK libraries

I'm trying to run a simple application in Qt creator using DCMTK libraries and it doesn't work as it should. I receive the following message:
error: undefined reference to `DicomImage::DicomImage(char const*, unsigned long, unsigned long, unsigned long)'
main.cpp:
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/dcmimage.h"
#include "iostream"
int main(int argc, char *argv[])
{
DicomImage *image = new DicomImage("test.dcm");
if (image != NULL){
std::cout << "hell yeah!";
}
return 0;
}
.pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2016-02-18T19:16:51
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#------------------
CONFIG += c++11
INCLUDEPATH += "C:\Program Files (x86)\DCMTK_1\include"
LIBS += -L"C:\Program Files (x86)\DCMTK_1\lib"
LIBS +=-ldcmimgle -ldcmdata -loflog -lofstd
win32:LIBS += -lAdvapi32 -lofstd -loflog -ldcmdata -ldcmnet -ldcmimage -ldcmimgle -lws2_32 -lnetapi32 -lwsock32
I think something is wrong with .pro file but I cannot figure out. I have included the necessary libraries and still no use.. I read that for DCMTK the order of libraries is important but I think it is already in order and cannot figure out what could be. Can you provide a solution to this problem?

C++ Qt MingW bad reloc 0xc address in section rdata

I'm with Qt 5.5 on Windows 10 64 bit with MingW compiler.
I'm trying to compile my project in debug mode => Works perfectly
But in release mode, I have these errors:
undefined reference to `TileMap::XYToNode(int, int) const'
undefined reference to `TileMap::XYToNode(int, int) const'
./release\perso.o: bad reloc address 0xc in section `.rdata'
collect2.exe:-1: erreur : error: ld returned 1 exit status
I have tried to do clean, qmake, and rebuild, but there are still errors.
I use some SFML dlls, and dlls I created. My TileMap class inherits a SFML class, and a micropather class (which is in one of the dlls).
Yes, I have tried Google before.
The .pro file:
TEMPLATE = app
TARGET = TealDemo
QT = widgets
SOURCES += ........
LIBS += -LC:/Qt/5.5/SFML/lib -LC:/Qt/5.5/micropather/lib -LC:/Qt/5.5/pathstore/lib
CONFIG(release): LIBS += -lsfml-graphics -lsfml-main -lsfml-window -lsfml-system -lmp -lpathstore
CONFIG(debug): LIBS += -lsfml-graphics-d -lsfml-main-d -lsfml-window-d -lsfml-system-d -lmpd -lpathstored
INCLUDEPATH += C:/Qt/5.5/SFML/include C:/Qt/5.5/micropather/include C:/Qt/5.5/pathstore/include
DEPENDPATH += C:/Qt/5.5/SFML/include C:/Qt/5.5/micropather/include C:/Qt/5.5/pathstore/include
HEADERS += .......
CONFIG += C++11 warn_on
debug {
DEFINES += TEAL_DEBUG
}
How to resolve this ?
Thanks
I deleted the inline before the function in the .cpp file, and it worked... Such strange.

Qt project set to version 5 but qtcreator still looking for qt4 header files?

Here is a screenshot from the project view:
Here is the .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2014-05-18T15:34:14
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = bedcoll
CONFIG += console
CONFIG -= app_bundle
QMAKE_CC = clang
QMAKE_CXX = clang++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -D_FILE_OFFSET_BITS=64
INCLUDEPATH += /usr/include/c++/4.8
INCLUDEPATH += /usr/include/boost
LIBS += -lboost_system
LIBS += -lboost_filesystem
LIBS += -lboost_program_options
TEMPLATE = app
SOURCES += \
src/util.cpp \
src/bedcoll.cpp \
src/main.cpp
HEADERS += \
src/collgen_memo.h \
src/util.h \
src/bedcoll.h \
src/error_enum.h
This project builds without any problem in a kubuntu 13.10, but after upgrading to 14.04, it gives the following error:
/usr/include/qt4/QtCore/qstring.h:1045: error: undefined reference to `QString::toAscii() const'
/usr/include/qt4/QtCore/qstring.h:880: error: undefined reference to `QString::free(QString::Data*)'
/usr/include/qt4/QtCore/qstring.h:879: error: undefined reference to `QString::shared_null'
Kubuntu 14.04 ships qt5 as default, but qtcreator is still looking for qt4, very confusing.
#Netjat is right, cleaning up solves the problem, in fact there is a shortcut, just right click on the project and choose "rebuild".

No rule to make target

I am trying to make QT application using C++ language which will record the video from analogue camera. so I included the videoInput.h and videoInput.lib files in my project but when i am trying to run the my project then the following error occurs.
the error is:
mingw32-make[1]: No rule to make target path/to/videoInputd.lib', needed by 'debug\test.exe'. Stop.
please give me the solution.
thanks for help.
Thanks for your reply. I already added LIBS.
My .pro file is
QT += core gui
QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h \
../../../"Qt Projects/Test projects/test" \
videoInput.h
FORMS += mainwindow.ui
INCLUDEPATH += E:\\ImageProcessing\\opencv_cmake_binaries\\install\\include
LIBS += -LE:\\ImageProcessing\\opencv_cmake_binaries\\install\\lib \
-lopencv_core244.dll \
-lopencv_highgui244.dll \
-lopencv_imgproc244.dll \
-lopencv_features2d244.dll \
-lopencv_calib3d244.dll
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -lvideoInput
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -lvideoInputd
INCLUDEPATH += $$PWD/../../../"Qt Projects/Test projects/test/videoInput"
DEPENDPATH += $$PWD/../../../"Qt Projects/Test projects/test/videoInput"
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/videoInput.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/videoInputd.lib
end of .pro file.
and I changed the build mode to release mode and then try to run then new error comes. The error is
error: redefinition of 'bool comInit'
error: 'bool comInit' previously declared here
static bool comInit;
error: redefinition of 'class videoInput'
class videoInput{
error: previous definition of 'class videoInput'
class videoInput{
These four errors are in videoinput.h file the compiler shows me like this.
And I know the file name is videoInput.h but compile output shows me that videoInputd.lib, needed by debug\test.exe
Do as Sebastian tells (add videoInput.lib to LIBS) and switch build mode to release, since you have only release version of this library (videoInput.lib, not videoInputd.lib).
I got the solution. When I was trying to include videoInput.lib file in Qt creator, at that time it was displayed above mention error.
So I used qt-vs-addin which is available here. qt-vs-addin.
I designed GUI in qt-vs-addin using visual studio 2010 for my application and include videoInput.lib file in visual studio 2010 and now my application is ready. This will be helpful for someone.
Thanks to all.
I had similare problem "No tule ro mske tsrgrt. Th rrason was syntax error like
testwx:($(OBJS).... Check your syntax line by line