AudioAnalyzer and macOS projects

When the AudioAnalyzer plugin is copied inside a macOS UE4 project we need to fix the linking of the thirdparty libraries used by this plugin. The packaging process puts an incorrect path only in this specific case, so we need to add manually the missing paths after the project is packaged.

To do that we need to use the install_name_tool command. If you want more details about that command you can check this tutorial MacOS Dynamic library linking

The script

We have created an script to automate the fixing process. So we only need to create an .sh file an copy this content inside.

#! /bin/bash

printhelp()
{
   echo ""
   echo "Usage: $0 AppFile ProjectName [-delete]" 
   echo -e "\tAppFile     Path to the .app file ./xxx/xxx/xxx.app"
   echo -e "\tProjectName Executable name (UE4 project name)"
   echo -e "\t[-delete]   Remove the rpath added by the script"
   exit 1
}

if [ "$1" == "" ]; then
    echo "Missing AppFile parameter"
	printhelp
fi

if [ "$2" == "" ]; then
    echo "Missing ProjectName parameter"
	printhelp
fi

PLUGIN_PATH="/Plugins/Marketplace/AudioAnalyzer/"

LIB_PATH_INSIDE_APP="@loader_path/../UE4/$2"${PLUGIN_PATH}"Source/Thirdparty/"

LIB_PATH_BIN_SDL2="SDL2/Libraries/Mac"
LIB_PATH_BIN_MP3="MPG123/Libraries/Mac"
LIB_PATH_BIN_OGG="OGG/Libraries/Mac"
LIB_PATH_BIN_VORBIS="VORBIS/Libraries/Mac"
LIB_PATH_BIN_FLAC="FLAC/Libraries/Mac"

APP_PATH="$1/Contents/MacOS/$2"

COMMAND_PARAM="-add_rpath"
if [ "$3" == "-delete" ]; then
	COMMAND_PARAM="-delete_rpath"
	echo "Deleting LC_RPATH..."
else
	echo "Adding LC_RPATH..."
fi

echo ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_SDL2}
install_name_tool ${COMMAND_PARAM} ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_SDL2} ${APP_PATH}
echo ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_MP3}
install_name_tool ${COMMAND_PARAM} ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_MP3} ${APP_PATH}
echo ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_OGG}
install_name_tool ${COMMAND_PARAM} ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_OGG} ${APP_PATH}
echo ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_VORBIS}
install_name_tool ${COMMAND_PARAM} ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_VORBIS} ${APP_PATH}
echo ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_FLAC}
install_name_tool ${COMMAND_PARAM} ${LIB_PATH_INSIDE_APP}${LIB_PATH_BIN_FLAC} ${APP_PATH}
echo "Done!"

With this script we can add and remove the fix, just we need to add the -delete parameter to remove that.

Now we need to find the packaged file and run this script in a console window

project_package

Open a window console in the script location and run it adding the path to the .app file and the name of the project, for our sample the call is:

./FixDynamicLibs.sh ./outAAMac/MacNoEditor/AA_MacLibrary.app/ AA_MacLibrary

If we want to remove the fix just run:

./FixDynamicLibs.sh -delete ./outAAMac/MacNoEditor/AA_MacLibrary.app/ AA_MacLibrary

To check if all the paths have been added we can run the otool command with -l parameter to list the load commands

otool -l ./pathToApp/AA_MacLibrary.app/Contents/MacOS/AA_MacLibrary

Now we can find the correct paths in the LC_RPATH section, and the game must be find the libraries inside their packaged file.

Support this blog!

For the past year I've been dedicating more of my time to the creation of tutorials, mainly about game development. If you think these posts have either helped or inspired you, please consider supporting this blog. Thank you so much for your contribution!