Qt application cannot find a 3rd party DLL and crashes - c++

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

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.

Errors trying to compile OpenCV QT code from Github

I'm new to the OpenCV / QT environment (and in programming in general). I'm trying to run this code:
https://github.com/Terranlee/Realtime_EVM
Can someone please tell me step by step what I need to install/compile in order to run this script on Windows 10? Not sure what versions to install or if it even matters.
I've tried following directions from here (https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows) but I keep getting 'undefined reference' errors which means I'm not referencing the libraries properly... or I need to edit the code somehow to point to my libraries but I'm not quite sure what to edit and how.
Thanks in advance and please excuse my noobieness!
-jay
Reply to answer
I compiled OpenCV using CMake per the wiki guide using the following commands:
mingw32-make -j 8
mingw32-make install
Once this was done, I opened Qt Creator and opened the Github EVM code by downloading the zip file then extracting it and opening the rvm.pro file.
Without making any changes, I tried to build the code and my first error was that it couldn't find "opencv_world310.dll" library.
I searched for it and found the file locally in the "E:\opencv\build\x64\vc14\bin" directory so I edited the rvm.pro file to look in that directory like so:
win32 {
OPENCVFOLDER = E:/_CODE_/_EXTERNAL_/OpenCV/my_git_build/
OPENCVVERSION = 310
INCLUDEPATH += E:\opencv\build\install\include
INCLUDEPATH += E:\opencv\build\x64\vc14\lib
CONFIG(release, debug|release) {
LIBS += -LE:\opencv\build\x64\vc14\lib
LIBS += -lopencv_world$${OPENCVVERSION}
}
CONFIG(debug, debug|release) {
DEFINES += DEBUG_MODE
LIBS += -LE:\opencv\build\x64\vc14\lib
LIBS += -lopencv_world$${OPENCVVERSION}d
}
This got rid of the initial error but then I get several 'undefined reference' issues afterward:
C:\Eulerian Real-Time OpenCV build\Realtime-Video-Magnification-master\build-rvm-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\main.o:-1: In function `ZN2cv6StringD1Ev':
E:\opencv\build\include\opencv2\core\cvstd.hpp:664: error: undefined reference to `cv::String::deallocate()'
C:\Eulerian Real-Time OpenCV build\Realtime-Video-Magnification-master\build-rvm-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\main.o:-1: In function `ZN2cv6StringaSERKS0_':
E:\opencv\build\include\opencv2\core\cvstd.hpp:672: error: undefined reference to `cv::String::deallocate()'
C:\Eulerian Real-Time OpenCV build\Realtime-Video-Magnification-master\src\main\threads\CaptureThread.h:42: error: undefined reference to `cv::VideoCapture::~VideoCapture()'
...... there are about 50 of these issues so I won't list them all.
Is it just a matter of correctly referencing the library?
In summary I'm just trying to run the Github code using Qt Creator, mingGW, CMake, & OpenCV. Please let me know how I need to edit the .pro file to link the library properly.
My OpenCV is in e:\opencv
Thanks again for the help and for your patience!
-Jay
There is very little info on what are the steps you are taking currently. Do you want to use Visual Studio / mingw? Here are some pointers:
You can open the pro file using Qt Creator
You can generate a Visual Studio compatible solution using qmake -spec <spec of the Visual Studio to use> -tp vc, to choose the spec see this answer.
With either of this you should have Qt includes/libraries set up.
The bad thing about the project is, that if you look at the .pro file, it explicitly uses Linux friendly include paths:
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += `pkg-config --libs opencv` -ldl
So, you will have to then add the include/library paths to OpenCV either inside Visual Studio or in the .pro file, if you are using Qt Creator. For example the link you used in your post on Qt/OpenCV has Windows friendly ones:
LIBS += D:\opencv-build\bin\libopencv_core320.dll
LIBS += D:\opencv-build\bin\libopencv_highgui320.dll
LIBS += D:\opencv-build\bin\libopencv_imgcodecs320.dll
LIBS += D:\opencv-build\bin\libopencv_imgproc320.dll
LIBS += D:\opencv-build\bin\libopencv_features2d320.dll
LIBS += D:\opencv-build\bin\libopencv_calib3d320.dll
So please explain in more detail what have you done so far, and which references (Qt/OpenCV) exactly are missing.

Importing libssh into Qt

I'm currently trying to import libssh into a Qt project I am working on. It appears that I have the library linked correctly as the project builds, but once I run the project it just crashes before anything really starts up. Which makes debugging difficult. If I comment out the line:
my_ssh_session = ssh_new();
Then everything runs as it should and no crash occurs. My .pro file looks like
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += sql
QT += script
QT += scripttools
QT += uitools
LIBS += -llibssh
INCLUDEPATH += $$quote(C:\libssh\include)
TARGET = white_wrapper
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
datafeeder.cpp \
dbfeeder.cpp \
xmlhelper.cpp \
hiddevice.cpp
HEADERS += mainwindow.h \
datasource.h \
datafeeder.h \
dbfeeder.h \
xmlhelper.h \
hiddevice.h
FORMS += mainwindow.ui
After looking online it looks like the problem could be dlls but after running a dll dependency application it looks like I have all the dlls needed so I guess I'm at a lose and would love some input thanks.
I was getting the same error message with libssh-0.7.1, Qt 5.2.1 and MinGW.
After some research it turned up that libssh
needs another two dynamic libraries which depends on: libeay32.dll and zlib1.dll. They are not included in libssh's distribution archive, therefore you have to download them yourself and copy next to libssh.dll (or somewhere on $PATH).
In my .pro file I have the following lines added (I installed libssh using their installer to Program Files (x86) directory):
# Libssh:
LIBS += -L$$PWD/'../../../../../Program Files (x86)/libssh/lib/' -lssh.dll
INCLUDEPATH += $$PWD/'../../../../../Program Files (x86)/libssh/include'
DEPENDPATH += $$PWD/'../../../../../Program Files (x86)/libssh/include'
Now my Qt application works without problems.

ACE (adaptive comminucations framework) wirh QT and MSVC2013 (VC12)

I am having trouble using ACE on Windows (have used it with great success on both OS-X and Linux(Ubuntu). It crashes in the ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m) function.
The OS is Windows 7 64bit.
I am building a 32bit application though (tried 64bit).
I followed http://www.dre.vanderbilt.edu/~schmidt/DOC_ROOT/ACE/ACE-INSTALL.html#win32 in order to build the 32bit libraries of ACE.
The ACE version is 6.4.0. The ACE_vc12.sln is build with VS2013_express.
My application (that works on OS-X using ACE) is build with QT5.7.0(32bit version) with kit configured to use MSCV2013 32bit configuration.
My project .pro file in QT looks like this (with some obfuscation):
`QT += core
QT += gui
CONFIG += debug
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
ACE = c:/ACE_wrappers
PathToIs = //Users/xxx/Dropbox/_Projects/xxx/is/yyy
LIBS = -L$$ACE/lib -lACEd -lpthread
TARGET = ZZZ_CSCI
include($$PathToIs/lib/ace.pri)
include($$PathToIs/Some_other.pri)
include($$PathToIs/Yet_another_pri.pri)
INCLUDEPATH += $$PathToIs/lib/shared
INCLUDEPATH += $$PathToIs/lib/utilities
TEMPLATE = app
SOURCES += main.cpp \
../../../../../lib/utilities/windows/UtilitiesWindows.cpp
HEADERS += \
$$PathToIs/lib/shared/GlobalDefs.h \
../../../../../lib/utilities/Utilities.h
INCLUDEPATH += C:/ACE_wrappers/include
DEPENDPATH += C:/ACE_wrappers/include`
The -lpthread causes a library not found link error.
What should I use for it in Windows (I believe that is linux osx specific library)?
LINK : fatal error LNK1104: cannot open file 'pthread.lib'
Out of desperation, I have removed -lpthread completely, which of course removes the linker error, but then when the application starts up, I get a crash in the function below:
ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m)
{
// ACE_OS_TRACE ("ACE_OS::thread_mutex_lock");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
::EnterCriticalSection (m);
return 0;
# else
return ACE_OS::mutex_lock (m);
# endif /* ACE_HAS_WTHREADS */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
The cursor of the debugger in QT points to the line ::EnterCriticalSection (m);
So my deduction is that some pthread library is required in windows for ACE to function correctly, but I have no idea where to find and more importantly, what to look for.
Any guidance would be much appreciated.
Regards
Ivor
So after a bit of trolling on the web, I saw that a company GlobeTOM uses ACE and I happen to know one of the owners. Gave him a call and they indicated that they used pthreads for Windows.
So got that from the WWWW and saw that I actually already tried it as well. Knowing that that path should work, was a big help.
This used the latest files, placed the dll in Windows/System32 and the lib and include files into the VC folder of MSVC2013. I used the 32bit libs.
Also then edited the .pro to include the libs. Actually, I right-clicked on the project in QT and selected "Add library", then selected "external library" and browsed to the .lib file. This adds the section into the .pro file. There are some specific options to select should you need to.
The lib to use is thus pthreadVC.lib.
Thanks to GlobeTOM for the pointers.
Ivor

QTCreator .pro file: Setting LIBS path depending on DEBUG / RELEASE

As a newbie to Qt I am writing a small project depending on another project, located in a parallel directory.
In my .pro file some .obj files are includes as below (which works). However, when creating a release I'd like to use the other project's release and not its debug path. I have checked the Qt variables and found the "TARGET example". But I failed to apply it to my LIBS, especially since the build can be for both debug_and_release , and I have no idea how to write the LIBS path then.
Pro file:
LIBS += -L"../../OtherApp/OtherApp-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug/debug"
LIBS += http.obj some other obj files
"Target example":
build_pass:CONFIG(debug, debug|release) {
unix: TARGET = $$join(TARGET,,,_debug)
else: TARGET = $$join(TARGET,,,d)
}
Can I write LIBS += -L"......."$$(TARGET)"......" , especially if target may contain both debug and release?
[Edit 1]
I have found a solution: https://stackoverflow.com/a/11612903/356726
By using the wizard (inlucde internal library) I got the following "code" created. This is most likely the solution:
win32:CONFIG(release, debug|release): LIBS += -LLIBS += -L"../../MyApp/current/MyApp-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Release/release"
else:win32:CONFIG(debug, debug|release): LIBS += -L"../../MyApp/current/MyApp-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug/debug"