Error : undefined reference to 'engOpen' - c++

Please, I'm looking for a solution to this problem
erreur : undefined reference to 'engOpen' when I try to call mtlb function for c++
I'm working on win64 with QT creator.
Here is my .pro file:
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
INCLUDEPATH += "C:\Program Files\MATLAB\R2012a\extern\include"
LIBS += -L "C:\Program Files\MATLAB\R2012a\bin\win64"
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)

LIBS += -L "C:\Program Files\MATLAB\R2012a\bin\win64"
You're only setting the lib path, you also have to point to the lib file:
LIBS += -L<path> -l<file without extension>
On Windows you can also just set the full path (with file), but the above format should work both with Unix and Windows. In your .pro you're mixing the Unix format and the Windows format.
Cf the Qt documentation.

Related

How to add the built from source boost library to qt creator on linux

I compiled the boost library from the source using the scripts that came with the source (below the commands that I wrote)
/bootstrap.sh —prefix=/libs
./b2 install
After the build, 2 new directories appeared in the libs directory, include and lib, respectively.
Next, I registered the path to boost in the pro file qt creator
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
INCLUDEPATH += I-/libs/include/boost
LIBS += -L/libs/lib
In theory, I specified the path to both the headers (include / boost) and the binaries (lib), but nevertheless, when I try to compile the test code, I get a bunch of errors. How to correctly register a pro file if I want to connect asio, on Linux, where did I go wrong? (set of errors)
You are not giving the library name in LIBS, only giving the path. Correct format is:
LIBS += -L<pathToLibrary> -l<libraryName>
Moreover INCLUDEPATH syntax is also incorrect. There's no need for I-.
INCLUDEPATH += /path/to/library
# e.g
INCLUDEPATH += libs/include/boost
And btw you don't need to link to anything if you are using asio only, since as far as I remember, Asio is header only so only include path will be necessary.

Qt application cannot find a 3rd party DLL and crashes

I am trying to build an application in QT that uses the libmodbus library. I am using MinGW 5.3 (Windows 7). The application will build without an error, but crashes when it attempts to run. The debug message says:
During startup program exited with code 0xc0000135
If I double-click the created executable file, there is an error that says:
libmodbus-5.dll is missing
from my computer.
Libmodbus was built with the same compiler. The include files are located in ../../codelibrary/MinGW63/libmodbus-master/src and the linker files are located in ../../codelibrary/QtMinGW53/libmodbus-master/src/.libs (.libs folder has both libmodbus.dll.a and libmodbus-5.dll).
If I add this library with Qt's 3rd party library wizard, then I get the following in my .pro file:
win32: LIBS += -L$$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/ -llibmodbus.dll
INCLUDEPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
DEPENDPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/libmodbus.dll.lib
else:win32-g++: PRE_TARGETDEPS += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/liblibmodbus.dll.a
This gives me the error:
-1: error: No rule to make target '../../codelibrary/MinGW63/libmodbus-master/src/.libs/liblibmodbus.dll.a', needed by 'debug\QTRosemount.exe'. Stop.
I then tried changing the .pro file to:
LIBS += -L$$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/libmodbus-5.dll
INCLUDEPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
DEPENDPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src
PRE_TARGETDEPS += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.libs/libmodbus.dll.a
This is when it will build without error and crash right away with code 0xc0000135 and a missing libmodbus-5.dll. I have tried many variations of the .pro paths that get this same error.
Note: I have been able to run console applications in Codeblocks with this library, not sure what I am running into with Qt.
How to fix this?
you can use an INSTALL SET and append it to the INSTALL list, as shown in QT documentation and illustrated below:
documentation.path = /usr/local/program/doc
documentation.files = docs/*
INSTALLS += documentation
For convenience, you may also use QMAKE_PRE_LINK. Now that you have some options, you may find further information in stackoverflow, such as in posts like this one.
Alternatively, I found that DEPENDPATH was incorrect. I have a folder in libmodbus that this needs to point to:
DEPENDPATH += $$PWD/../../codelibrary/QtMinGW53/libmodbus-master/src/.deps
The program compiles correctly with this changed

QGIS cannot find headers file

I'm trying to create a custom QGIS desktop application with Qt 5.9.1
I have downloaded OSGeo4W (x64) geospatial software set and the Github C++ QGIS samples but I'm facing an error at compile time:
Cannot open include file: 'qgsmapcanvas.h': No such file or directory
Actually none of the above headers files are under OSGeo4W folder:
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmaplayerregistry.h>
#include <qgsrasterlayer.h>
#include <qgsmapcanvas.h>
But..shouldn't they be in dll libraries (eg qgis_core, qgis_gui ... ) ?
Anyway, this is my *.pro file:
TEMPLATE = app
TARGET = qgis_example4
QT = sql network svg gui core xml
LANGUAGE= C++
INCLUDEPATH += "C:\\OSGeo4W64\\include"
LIBS += -L"C:\\OSGeo4W64\\apps\\qgis\\bin" -lqgis_core -lqgis_gui -lgdal_i -lgeos_c
DEFINES+=CORE_EXPORT=__declspec(dllexport)
DEFINES+=GUI_EXPORT=__declspec(dllexport)
CONFIG += qt gui exceptions stl warn_on debug thread
RESOURCES += resources.qrc
FORMS += mainwindowbase.ui
HEADERS = mainwindow.h
SOURCES = main.cpp \
mainwindow.cpp
PS: there is a similar question on stackiverflow but I repeated it because the answers given did not give the solution
Solved: the needed headers file could be found within the "qgis-dev" branch of the project.
OSGeo4W : For users that cannot use OSGeo4W for some reason or just prefer it there is also a weekly snapshot of qgis-dev from OSGeo4W as standalone installer
After the installation you can find header in:
C:/Program Files/QGIS 2.99/apps/qgis-dev/include
So this is my .pro file
TEMPLATE = app
TARGET = qgis_example4
QT = sql network svg gui core xml
LANGUAGE= C++
INCLUDEPATH += "C:/Program Files/QGIS 2.99/include"
INCLUDEPATH += "C:/Program Files/QGIS 2.99/apps/qgis-dev/include"
LIBS += -L"C:/Program Files/QGIS 2.99/apps/qgis-dev/bin" -lqgis_core -lqgis_gui
DEFINES+=CORE_EXPORT=__declspec(dllexport)
DEFINES+=GUI_EXPORT=__declspec(dllexport)
CONFIG += qt gui exceptions stl warn_on debug thread
RESOURCES += resources.qrc
FORMS += mainwindowbase.ui
HEADERS = mainwindow.h
SOURCES = main.cpp \
mainwindow.cpp
Although the files are now present, I still not able to run QGIS samples. Maybe I'll move to other sample or I'll do my custom basic application.

Qt Creator linker error: LNK1104: cannot open file 'opencv_core249d.lib'

I'm building a Kinect app using Qt and C++ and I need to use the OpenCV library. I have correctly installed OpenCV and included the OpenCV header <opencv2\opencv.hpp> in my source file, and that's the only header I'll be using. I tried building my project in visual studio and it worked out fine, but now I'm trying to build the project in Qt Creator and it's giving me this build error:
LNK1104: cannot open file 'opencv_core249d.lib'
So here is my project file:
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------
TEMPLATE = app
TARGET = MM_demo
DESTDIR = ../Debug
QT += core opengl widgets gui
CONFIG += debug
#include directories
KINECT_INC_DIR = $$(KINECTSDK10_DIR)inc
OPENCV_INC_DIR = $$(OPENCV_DIR)\include
#library directories
OPENCV_LIB_DIR = $$(OPENCV_LIBRARY_DIR)
KINECT_LIB_DIR = $$(KINECTSDK10_DIR)lib\amd64
DEFINES += QT_OPENGL_LIB QT_WIDGETS_LIB
INCLUDEPATH += $$KINECT_INC_DIR $$OPENCV_INC_DIR
DEPENDPATH += $$OPENCV_LIB_DIR $$KINECT_LIB_DIR
message(opencv lib directory $$OPENCV_LIB_DIR)
message(kinect lib directory $$KINECT_LIB_DIR)
LIBS += -L"." \
-lopencv_core249d \
-lkinect10 \
MOC_DIR += ./GeneratedFiles/debug
OBJECTS_DIR += debug
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(MM_demo.pri)
I'm using Qt 5.5.2 MSVC2013 64bit on Window 8.1. My OpenCV environment variables are: OPENCV_DIR: C:\opencv\build and OPENCV_LIB_DIR: C:\opencv\build\x64\vc10\lib
My OpenCV include directory is C:\opencv\build\include and its library directory is C:\opencv\build\x64\vc10\lib. I'm sure I have put the right include and library paths in the .pro file. I've been searching for a solution all day and saw some similar linker issues on the web but none of them solved my issue. I'll be thankful to anyone who has an idea of what's going wrong with my .pro file or anything else.
You have set OPENCV_LIB_DIR as environment variable but it needs to be OPENCV_LIBRARY_DIR because the operating system has no information on the first term in the line below but it will look for the second variable:
OPENCV_LIB_DIR = $$(OPENCV_LIBRARY_DIR)

Opencv sample in Qt crashes immediately with the error 'The program has unexpectedly finished'

I tried to create a simple Opencv application in Qt and upon running, the whole application is crashed. If I comment out the opencv related codes from the project, the project runs just fine.
What I did:
Downloaded the Qt 5.5.0 VS2013 64bit version
Downloaded the OpenCV 3.0
Downloaded the Cmake 3.3.2
There were already prebuilt binaries in when I extracted the Opencv package, But all tutorials on the net wanted me to recompile the source codes so did I. The package contains:
build
sources
created a new folder named mymade to hold the binaries next to the other two directories. So it now looks like this:
build
mymade
sources
Steps:
Fired up CMake, specified the source folder from the extracted files
and specified mymade as the output for binaries.
checked all options that had a opencv in their names, plus Qt! and configured it and subsequently generated the files.
This is the resulting contents:
So all is done and I now need to build the binaries. I opened OpenCV.sln and compiled the release and debug binaries. The dlls are placed inside bin directory, and the lib files are placed inside lib folder.
Now it's the time to configure the Qt projects .pro file, so I used the header files from build directory, and for libs I used the lib folder from mymade folder. This is the first configuration that I came up with, which compiles without any linker issues, but crashes just immediately.
The initial changes in project file :
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib
FORMS += mainwindow.ui
Doing this in project file as it was suggested by answers like this didn't do any good either:
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib
FORMS += mainwindow.ui
This fails as well:
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300
FORMS += mainwindow.ui
So what is the problem here?
Update
As it was pointed out by #Miki, Qt couldn't find the opencv dlls (the configs above were OK but), And to solve this problem, one only needs to add the directory containing dlls to the PATH variable, there you are good to go and everything should be fine now.
From the comments to question it turns out that the program didn't find OpenCV dll.
You can:
Copy the required dll in the same folder of the .exe
Add the folder containing the dll to the PATH. You need to restart Qt Creator for changes to take effect.