How to build crashpad for Qt application - c++

I am developing Qt application and I would like to use crashpad to report crashes. I have downloaded sources and built them.
Now I would like to link those statically to my application.
When I go to out folder I see a lot of .a files. Which one should I choose?
> find ./out -name *.a
./obj/handler/libhandler.a
./obj/snapshot/libsnapshot.a
./obj/snapshot/libtest_support.a
./obj/test/libtest.a
./obj/test/libgtest_main.a
./obj/test/libgmock_main.a
./obj/util/libutil.a
./obj/third_party/mini_chromium/mini_chromium/base/libbase.a
./obj/third_party/gtest/libgtest_main.a
./obj/third_party/gtest/libgtest.a
./obj/third_party/gtest/libgmock.a
./obj/third_party/gtest/libgmock_main.a
./obj/minidump/libminidump.a
./obj/minidump/libtest_support.a
./obj/client/libclient.a
Also I have built it using this command:
build/gyp_crashpad.py -Dmac_deployment_target=10.12
I do not know if I should add some parameters
Could someone please help?
Thanks in advance

Build Crashpad via gn and ninja, where gn generates a build configuration, and ninja does the actual building.
For a macOS Qt application to generate minidumps and upload them to a remote server it will need to be linked with the Crashpad libraries libcommon.a, libclient.a, libutil.a, libbase.a, mig_output.a:
# Crashpad libraries
LIBS += -L$$PWD/Crashpad/Libraries/MacOS/$$ARCH -lcommon
LIBS += -L$$PWD/Crashpad/Libraries/MacOS/$$ARCH -lclient
LIBS += -L$$PWD/Crashpad/Libraries/MacOS/$$ARCH -lbase
LIBS += -L$$PWD/Crashpad/Libraries/MacOS/$$ARCH -lutil
LIBS += -L$$PWD/Crashpad/Libraries/MacOS/$$ARCH -lmig_output
The application will also need to be linked with the system library bsm, and frameworks AppKit and Security:
# System libraries
LIBS += -L/usr/lib/ -lbsm
LIBS += -framework AppKit
LIBS += -framework Security
Additionally, you'll need to package crashpad_handler with your application and ensure that it is available at runtime.
More information about building Crashpad can be found here.
An example macOS Qt application that has been integrated with Crashpad can be found here.

Maybe type this in your code:
sys._excepthook = sys.excepthook
def my_exception_hook(exctype, value, traceback):
# Print the error and traceback
print(exctype, value, traceback)
# Call the normal Exception hook after
sys._excepthook(exctype, value, traceback)
sys.exit(1)
# Set the exception hook to our wrapping function
sys.excepthook = my_exception_hook
Also, import sys. This Code prints the error and reports it.

Related

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

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 for iOS: How to deploy a dylib shared library with my application

I'm having a hard time deploying dynamic shared libraries on iOS.
To isolate and expose the problem, I have a very simple "HelloWorld" project: A library exporting class with a function returning "Hello World" and a program using the class and displaying the message.
I'm using QtCreator with Qt 5.5.
I'm able to generate the .dylib file and link my program. But, when I deploy it on the iPhone, I get the error:
Démarrage des processus distants.
dyld: Library not loaded: libMyLib.1.dylib
Referenced from: /private/var/mobile/Containers/Bundle/Application/D6942CCE-828D-4C10-86DA-F7DA7ADF7449/MyApp.app/MyApp
Reason: image not found
On Android, I had the same kind of issue and could fix it by manually adding the shared library to the final package (apk) file, using ANDROID_EXTRA_LIBS. But I can find no equivalent for iOS.
Here are my .pro files. Full project can be downloaded here. I reported this to Qt as a bug, but if one could propose a kind of workaround this would help!
MyLib.pro:
QT -= core gui
TARGET = MyLib
TEMPLATE = lib
DEFINES += MYLIB_LIBRARY
SOURCES += mylib.cpp
CONFIG += shared
HEADERS += mylib.h\
mylib_global.h
MyApp.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyApp
TEMPLATE = app
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
INCLUDEPATH += ../MyLib
LIBS += ../MyLib/libMyLib.dylib
I'd like the solution to be all embedded in QtCreator. The only think that should be changed here is one of the two .pro files. Possibly with post-build calls to MACOS commands...? Or just a post-build instruction in MyApp.pro to copy the dylib in the right place (.app target folder) before application is deployed? I'm really surprised this is not covered silently by QtCreator....
Note: This question suggests to set DYLD_LIBRARY_PATH. But I have no clue hox to do this within the MyApp.pro file nor how it will help upon iOS deployment (as DYLD_LIBRARY_PATH can be set the MAC PATH to the lib, not the iPhone PATH to the lib...)
1) In your library project make sure your dylibs have installname #rpath/mylib.dylib or such. E.g. by adding QMAKE_SONAME_PREFIX = #rpath to your library .pro file.
(You can check by looking at the first line of otool -L /path/to/libmylib.dylib. If the library is a prebuilt 3rdparty one, change it with install_name_tool -id #rpath/libmylib.dylib)
2) add the following to the application .pro file
# link to the lib:
LIBS += -L../mylib -lmylib
# make the app find the libs:
QMAKE_RPATHDIR = #executable_path/Frameworks
# deploy the libs:
mylib.files = $$OUT_PWD/mylib/libmylib.1.dylib
mylib.path = Frameworks
QMAKE_BUNDLE_DATA += mylib
I came up with a workaround for that, in case it could help anyone.
Build your library statically instead of dynamically (replace CONFIG += shared by CONFIG += staticlib
Now, compiler will generate *.a files instead of *.dylib, You must use this extension when linking libraries (replace LIBS += myLib.dylib by LIBS += myLib.a)
If your library was only linked by a program, you are done
If your library, let's call it (A), was used by another library (B), then (B) should not link with it anymore (No LIB flag in B.pro). Only the top level program will link with all your static libraries.
With this approach, I could deploy a program using 15 libraries on an iPhone with QtCreator.

app-file not running on different mac

I have created an app-file with Qt. It contains openGL, Qt and c++ code.
My pro file looks like this:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += openglscene.h \
glwidget.h
QT += opengl
OTHER_FILES +=
RESOURCES += \
images.qrc
mac: LIBS += -framework GLUT
else:unix|win32: LIBS += -lGLUT
FORMS +=
I get the following error message, when trying to run the app-file on a different mac:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Application Specific Information:
dyld: launch, loading dependent libraries
Dyld Error Message:
Library not loaded: /Developer/QtSDK/Desktop/Qt/473/gcc/lib/QtOpenGL.framework/Versions/Current/QtOpenGL
Referenced from: /Users/USER/Desktop/*/model.app/Contents/MacOS/model
Reason: image not found
The other macs dont have Qt installed. As it seems I somehow need to include an openGL-framework. How is it possible to do so that other users of my app would be able use it?
You need to include all your application's dependencies including Qt in the app bundle. qmake doesn't take care of this by itself. Qt comes with a little tool, macdeployqt, which might do what you need. A more sophisticated solution is using CMake and DeployQt4.cmake

Problem installing QCA-OSSL (part of the Qt Cryptographic Architecture) plugin on Windows 7

I have been trying to use QCA (Link) on my Windows PC for a couple of days now, works fine on my linux box, just can't get it working with Windows.
So i followed all the instructions for installing QCA and then the ossl plugin for QCA. The QCA works fine but for some reason the plugin isn't showing up in my Qt Creator nor am I able to use some of the functions in the plugin.
I used the qcatool2.exe that comes with QCA to check my plugins using
qcatool2 plugins --debug
and get this error message:
plugin: qca-ossl2.dll: failed to load: The plugin 'C:/Qt/2010.05/qt/plugins/crypto/qca-ossl2.dll' uses incompatible Qt library. Expected build key "Windows mingw debug full-config", got "Windows mingw release full-config"
Now this seems to me as if qt requires the plugin to be compiled in debug mode (as to get the build key to contain debug rather than release) so I added
CONFIG += debug
to my plugin's project file and ran qmake and mingw32-make as usual but this seems to have had no effect.
My project file for the plugin is now:
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
load(winlocal.prf)
isEmpty(WINLOCAL_PREFIX) {
error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
}
OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
CONFIG += debug
Has anyone got any ideas? If you need anymore details just ask, I've tried to be as thorough as possible. Thanks
Tom
I've been struggling with a similar situation: qca-ossl builds fine on linux and not at all on windows. I just hit a breakthrough which might help you as well.
Versions and Patches
qtsdk-2010.05
qca-2.0.3
qca-ossl-r1190163 (from the repository)
openssl-1.0.0b
First of all, if you're using a newer version (0.9.7+, I think) of OpenSsl, you may need to use the qca-ossl version from the repository since it patches some incompatibilities. I also needed to comment out some lines in the new qca-ossl.cpp file dealing with SHA224, SHA256, SHA384, and SHA512 to avoid build errors. I'm using qca-ossl for the ciphers, so I'm not worried about hashing and didn't investigate the errors very much.
Fixing It
The windows build problems were many fold for me, but most of them stem from the shoddy build setup for the windows version of the plugin. It's nice having a little configure script for the linux side of things, but what about windows? We need to do a little extra work.
Some of this extra work is because I've chosen non-standard locations for the support libraries of my application. Qca and OpenSsl both exist within the project's directory structure in a libraries/ directory. My guess is that you've done something similar if you are trying to cross compile your application, but even if you didn't the following should help.
Finding OpenSsl
Qca-ossl wont build very well if it can't find the library it's supposed to connect to... :) So let's specify directly where it is. Comment out the lines relating to winlocal.prf and the changes that stem from it in qca-ossl.pro. We will directly specify where to find openSsl.
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
# Rather than rely on the winlocal.prf file, we will specify the location of the openssl
# by hand when running qmake.
#
# load(winlocal.prf)
# isEmpty(WINLOCAL_PREFIX) {
# error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
# }
#
# OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
Now we have direct access to the $$OPENSSL_PREFIX environment variable in the .pro file. We can set it when we call qmake by doing the following.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b"
You should be able to use backward slashes or forward slashes. Here I choose forward since Qt has deprecated them since 4.7.
Alternatively, you could set the OPENSSL_PREFIX variable directly in the .pro file.
Finding Qca
After comparing the unix and windows makefiles for qca-ossl, oddly enough, it never includes the qca libraries for building or linking! ?!?! This led to an "Undefined interface" error on the Q_INTERFACES(QCAPlugin) line of the opensslPlugin class definition at the end of qca-ossl.cpp.
To avoid this, we will need to explicitly define the include and library paths by hand. Expanding on the qmake line from the last section the final qmake line is as follows.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b" "INCLUDEPATH+=C:/path/to/qca-2.0.3/include/QtCrypto" "LIBS+=-LC:/path/to/qca-2.0.3/lib -lqca2"
"Installing" Qca-ossl
After running the qmake line above and running a plain ol' make, you'll need to install Qca-ossl. You can copy the resulting dll from the lib/ directory to your Qt's plugins directory, which if you're using my versions defaults to C:\Qt\2010.05\qt\plugins\crypto. Alternatively, you can move it to a crypto directory that's at the root level of your project's directory structure such as C:\path\to\my\project\crypto.
I hope this helps!
Actually, you can try this tutorial QCA+OpenSSL on Window. It's work well.
By the way, I can make use of QCA with AES 256 on Window. But i can't use it on Symbian. Any idea to do it?
Related Post