Ad N
Ad N

Reputation: 8396

How to make macdeployqt change the library names inside QtWebEngineProcess.app when it copies over QtWebEngineCore framework

Edit: using Qt 5.9.1, installed with Homebrew

Following a comment in this other question, we are trying to use macdeployqt to prepare the distribution of the OSX bundle of a Qt based application.

This tool is correctly copying over all Qt dependencies (and even some non Qt libraries) inside the bundle. It also changes the dependent library names inside both the application itself and the copied libraries.

It also successfully copies the QtWebEngineProcess.app contained in the Helpers folder of QtWebEngineCore.framework.

 Problem

A problem is that it is not changing the dependent library names inside QtWebEngineProcess, so the bundle is not relocatable (as QtWebEngineProcess refers to its dependent library by absolute paths that are only valid on the development machine). Trying to run the app on a "client" machine, one would thus get the error:

dyld: Library not loaded: /usr/local/Cellar/qt/5.9.1/lib/QtWebEngineCore.framework/Versions/5/QtWebEngineCore Referenced from: Business.app/Contents/Frameworks/QtWebEngineCore.framework/Helpers/QtWebEngineProcess.app/Contents/MacOS/QtWebEngineProcess

We tried to manually fix this application, by editing QtWebEngineProcess to replace the absolute part of the path to the Qt libraries by @loader_path/../../../../../../../../Frameworks/.

This only moves the problem forward: now QtWebEngineProcess seems to correctly load its dependent libraries, but the dependent libraries themselves cannot load their dependent libraries anymore, since their install name is starting with @executable_path, and QtWebEngineProcess executable lives in a different folder from Business executable. Hence the error:

dyld: Library not loaded: @executable_path/../Frameworks/QtQuick.framework/Versions/5/QtQuick
Referenced from: Business.app/Contents/Frameworks/QtWebEngineCore.framework/Versions/5/QtWebEngineCore


Is macdeployqt broken when it comes to an application using Qt's web engine?

Is there a way to have it work without manually re-changing all Qt install names in the bundle?

Upvotes: 4

Views: 1143

Answers (3)

skalee
skalee

Reputation: 12675

I've crafted a following script, which fixes these paths with install_name_tool:

#!/bin/bash
set -x -e

pushd MyApp.app/Contents/Frameworks/QtWebEngineCore.framework/Helpers/QtWebEngineProcess.app/Contents/MacOS

for LIB in QtGui QtCore QtWebEngineCore QtQuick QtWebChannel QtQml QtNetwork QtPositioning
do
    OLD_PATH=`otool -L QtWebEngineProcess | grep ${LIB} | cut -f 1 -d ' '`
    NEW_PATH="@loader_path/../../../../../../../${LIB}.framework/${LIB}"
    install_name_tool -change ${OLD_PATH} ${NEW_PATH} QtWebEngineProcess
done

popd

Note the lack of quotes around ${OLD_PATH} when used as an install_name_tool argument. This is because value of OLD_PATH has some extra white spaces around the path, which shouldn't be preserved. The lack of quotes is typically harmless if Qt has been installed via Homebrew, as these paths do not contain white spaces. However, this could be improved.

Important: This fix is enough to make Simple Browser (from Qt examples) running. But in more advanced projects, more fiddling may be required.

Upvotes: 0

Ad N
Ad N

Reputation: 8396

Following one of Dmitry's comment on the original question, I finally took the time to test with an official distribution of Qt 5.9.1 for OS X, and it turns out he was right. The macdeployqtdistributed with the official binaries of Qt is handling QtWebEngineProcess.app just fine.

The version of this utility distributed with homebrew installation's of Qt is bogus, at least in 5.9.1

Upvotes: 1

htzfun
htzfun

Reputation: 1448

So far macdeployqt works fine for me on local machine. On CI you might encounter problem that artifacts are broken in somewhat way like this.

That happens if you copy your application with cp -r or zip it without -y option then all symlinks will be resolved inside the app and it won't work because there will be many copies of QtWebEngineProcess. Also it will break your signature if you sign app.

Solution is to use cp -a and zip -r -y instead - the last one worked for me instead of using plugin for artifacts.

Upvotes: 0

Related Questions