undefined reference in Qt creator for DCMTK libraries - c++

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?

Related

How to link a dynamic library in QtCreator use qmake and MinGW32?

I am trying to use hiredis and libevent in my project, I downloaded their source code and compiled them with CmakeGUI and MinGW32. Then i got the header files and those library files.
libevent.a
libevent.dll
libevent.dll.a
libevent_core.a
libevent_core.dll
libevent_core.dll.a
libevent_extra.a
libevent_extra.dll
libevent_extra.dll.a
libhiredis.dll
libhiredis.dll.a
Then I wrote some test programs to use these libraries, but could not link successfully
The error looks like this:
error: undefined reference to `redisConnect'
here is my pro file and code.
#my pro file
#hiredis
INCLUDEPATH += $$PWD/include/hiredis
LIBS += -L$$PWD/lib/ -llibhiredis.dll
#event2
INCLUDEPATH += $$PWD/include/libevent
LIBS += -L$$PWD/lib/ -llibevent.dll
LIBS += -L$$PWD/lib/ -llibevent_core.dll
LIBS += -L$$PWD/lib/ -llibevent_extra.dll
#include "hiredis.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow) {
ui->setupUi(this);
redisContext *asd = redisConnect("127.0.0.1", 6379);
}
This is the compile output
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Test.exe release/main.o
release/mainwindow.o release/moc_mainwindow.o
-LC:\Users\VC\Desktop\Test\lib C:\Users\VC\Desktop\Test\lib\libhiredis.dll.a
C:\Users\VC\Desktop\Test\lib\libevent.dll.a
C:\Users\VC\Desktop\Test\lib\libevent_core.dll.a
C:\Users\VC\Desktop\Test\lib\libevent_extra.dll.a
D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libQt5Widgets.a
D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libQt5Gui.a
D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libQt5Core.a
-lmingw32 D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libqtmain.a
-LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.6.11-win32\lib
-LC:\Utils\postgresql\pgsql\lib -lshell32
release/mainwindow.o:mainwindow.cpp:(.text+0x2c9): undefined reference to `redisConnect'
I tried two different libraries(libevent and hiredis) and got similar results, what am I doing wrong?
thank you
Try to remove the .dll, just give the name of the lib, I mean include the lib like this :
INCLUDEPATH += $$PWD/include/hiredis
INCLUDEPATH += -L$$PWD/lib
LIBS += -L$$PWD/lib/ -llibhiredis
Then clean the project and run qmake.
I once set a 64-bit version of MinGW in environment variables, but I forgot
When I changed it to the 32-bit MinGW path, the compilation was successful and the dynamic library can be used

Using Caffe in Qt Console Application

I am trying to use caffe in Qt IDE,
I have the following code:
#include <QCoreApplication>
#include "caffe/caffe.hpp"
using namespace caffe;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Caffe::set_mode(Caffe::CPU);
return a.exec();
}
I just wanted to set Caffe in CPU Mode.
I have the following .pro file
QT += core
QT -= gui
CONFIG += c++11
TARGET = CaffeTest_v0
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /home/ahmet/caffe/include \
/home/ahmet/caffe/distribute/include \
/home/ahmet/caffe/build/lib
LIBS += -lcaffe
SOURCES += main.cpp
I have the following problem :
My problem is I want to set caffe in CPU mode, I installed caffe in CPU mode.
How can I set Caffe in CPU mode in main?
P.S. I believe I installed caffe corectly, because I tested by the following command in gnome terminal
caffe train -solver lenet_train_solver.prototxt
I also searched the following websites:
http://tzutalin.blogspot.co.uk/2015/05/caffe-on-ubuntu-eclipse-cc.html
Error while including Caffe in C++ Project using cmake
https://github.com/BVLC/caffe/issues/3317
https://groups.google.com/forum/#!topic/caffe-users/DAv5EcsvbIU
In .pro file, I should add
DEFINES += CPU_ONLY
solves the problem.
Final .pro file is below:
QT += core
QT -= gui
CONFIG += c++11
TARGET = CaffeTest_v0
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
DEFINES += CPU_ONLY
INCLUDEPATH += /home/ahmet/caffe/include \
/home/ahmet/src/caffe/proto \
/usr/include/boost
LIBS += -L/home/ahmet/caffe/build/lib \
-lcaffe \
-L/usr/lib/x86_64-linux-gnu \
-lboost_system
SOURCES += main.cpp

link error- Qt Creator OpenCV Ubuntu

I am currently having a link error with Qt.
I cant compile my code since i got the error message:
error: undefined reference to `cv::imread(cv::String const&, int)'
Heres the content of my .pro
QT += core
QT -= gui
TARGET = edge_detection
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include/opencv2
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
Heres my simple code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main(){
cv::Mat img;
img=cv::imread("/home/cgross/Downloads/2.jpg");
return 0;
}
I am not sure of where is the problem
includepath must show opencv and opencv2.just like that:
INCLUDEPATH += C:\\opencv-2.4.6.1\\build-msvc2012\\install\\include
LIBS+=-LC:\\opencv-2.4.6.1\\build-msvc2012\\install\\lib \
-lopencv_calib3d246d \
-lopencv_contrib246d \
-lopencv_core246d \
-lopencv_features2d246d \
-lopencv_flann246d \
lıbs must show .lib file
Your code builds and runs just fine for me on a somewhat antique stock ubuntu 12.10 with opencv 2.3 from the distribution packages.
It picks up a cv::imread(std::string const &, int) from libopencv_highgui.

Qt/C++ linkage error (undefined reference)

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?

OpenCV with Qt: The program has unexpectedly finished

I am trying to configure OpenCV with Qt Creator 2.7.0 (Qt 5.0.2) on windows 8 64bit.
While executing my program, I get the following error:
The program has unexpectedly finished.
This is my main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
IplImage *image = cvLoadImage("E:\\lena.jpg"); //If this is removed, the program runs OK
return a.exec();
}
My .pro file is
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
unix:!mac {
message("* Using settings for Unix/Linux.")
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}
## OpenCV settings for Mac OS X
macx {
message("* Using settings for Mac OS X.")
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}
## OpenCV settings for Windows and OpenCV
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\OpenCV\\opencv\\build\\include" \
"C:\\OpenCV\\opencv\\build\\include\\opencv" \
"C:\\OpenCV\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\OpenCV\\opencv\\build\\x64\\mingw\\lib" \
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
}
Environment Variables are:
OPENCV_DIR:C:\OpenCV\opencv\build\x64\mingw Path:
G:\5.0.2\Tools\MinGW\bin;G:\Qt\5.0.2\mingw47_32\bin
What could be the problem ?
I suggest you use the OpenCV 2.x API if possible. The error handling is better.
This would be cv::Mat image = cv::imread("E:\lena.jpg");
If the image is empty, it means you have the wrong path.
Also, make sure the opencv dll are in the path of your executable (core, highgui and imgproc).
You might need to change
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
to
-lopencv_core244d \
-lopencv_highgui244d \
-lopencv_imgproc244d
note 'd' at the end of each lib (if you are to build in debug)
Have you solved the problem?
Have you tried adding system("PAUSE"); after the return a.exec(); ?
Just some extra notes:
Also try
try
{
...
}
catch (Exception e)
{
...
}
to see if you can find the error
thirdly, check the file permissions for lena.jpg
Lastly, see if you can use the path E:\lena.jpg