Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Crashpad with a Windows Qt application

We are trying to integrate Crashpad with our Qt application and have run into several errors. We built Crashpad and attempted to link it to our application using the following snippet from the .pro file:

# Crashpad rules for Windows
win32 {
    LIBS += -L$$PWD/Crashpad/Libraries/Windows/ -lbase
    LIBS += -L$$PWD/Crashpad/Libraries/Windows/ -lclient
    LIBS += -L$$PWD/Crashpad/Libraries/Windows/ -lutil
}

Upon building, we got a ton of linker errors similar to the following:

base.lib(base.file_path.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in main.obj

We saw this post and decided to build Crashpad using the /MDd flag. After copying the new libraries into the directory listed above building with Qt yielded the following error:

fatal error C1007: unrecognized flag '-Ot' in 'p2'

Why is MSVC throwing this error? We are building using the 14.0 MSVC toolset.

like image 400
bobbyg603 Avatar asked Jan 25 '23 23:01

bobbyg603


1 Answers

The issue here ended up being a toolset mismatch. Ninja built Crashpad using the MSVC 2019 toolset. The version of Qt installed on the machine in question was 5.14.2 which used a MSVC 2017 toolset. Once we installed the 5.15.0 kits and built with the MSVC 2019 build configuration this error went away.

Additionally, once we solved the previous errors 4 new errors appeared:

util.lib(util.registration_protocol_win.obj) : error LNK2001: unresolved external symbol __imp_BuildSecurityDescriptorW
util.lib(util.registration_protocol_win.obj) : error LNK2001: unresolved external symbol ConvertStringSecurityDescriptorToSecurityDescriptorW
util.lib(util.registration_protocol_win.obj) : error LNK2001: unresolved external symbol __imp_BuildExplicitAccessWithNameW
base.lib(base.rand_util.obj) : error LNK2001: unresolved external symbol SystemFunction036

These errors were solved by linking with Advapi32:

# Crashpad rules for Windows
win32 {
    LIBS += -L$$PWD/Crashpad/Libraries/Windows/ -lbase
    LIBS += -L$$PWD/Crashpad/Libraries/Windows/ -lclient
    LIBS += -L$$PWD/Crashpad/Libraries/Windows/ -lutil
    LIBS += -lAdvapi32
}

Edit: After revisiting this, we found another solution is to turn off Whole Program Optimization which allows you to mix and match versions of MSVC building Crashpad and Qt.

Turning off Whole Program Optimization can be done by adding /GL- to extra_cflags. The following snippet works in Windows CMD (does not work in PowerShell):

gn gen out\MD --args="extra_cflags=\"/MD /GL-\""

A sample Windows Qt application integrated with Crashpad can be found here.

like image 149
bobbyg603 Avatar answered Jan 29 '23 13:01

bobbyg603