# Packaging for macOS doesn't add correct RPATH for thirdparty dependencies

**URL:** <https://forums.unrealengine.com/t/packaging-for-macos-doesnt-add-correct-rpath-for-thirdparty-dependencies/136944>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [January 23, 2020, 12:22am UTC](https://forums.unrealengine.com/t/packaging-for-macos-doesnt-add-correct-rpath-for-thirdparty-dependencies/136944 "2020-01-23T00:22:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_5a7a8c01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5a7a8c01](https://forums.unrealengine.com/u/anonymous_user_5a7a8c01)\
**Post date:** [January 23, 2020, 12:22am UTC](https://forums.unrealengine.com/t/packaging-for-macos-doesnt-add-correct-rpath-for-thirdparty-dependencies/136944/1 "2020-01-23T00:22:34Z")

</div>

I have a plugin in my project that links to third-party library. Everything builds, but when I package my project for macOS, I can see the library as a dependency in otool output:

```auto

otool -L <...>/MacNoEditor/game.app/Contents/MacOS/game

```

However, Unreal does not create proper rpath that points to it and as a result when trying to start the game, it crashes because it can’t find the library.  
All I see are rpaths for UE’s thirdparty libraries:

```auto

otool -l <..>/MacNoEditor/game.app/Contents/MacOS/game | grep RPATH -A2
          cmd LC_RPATH

      cmdsize 32

         path @loader_path/ (offset 12)

--

          cmd LC_RPATH

      cmdsize 32

         path @executable_path/ (offset 12)

--

          cmd LC_RPATH

      cmdsize 72

         path @loader_path/../UE4/Engine/Binaries/ThirdParty/PhysX3/Mac (offset 12)

--

          cmd LC_RPATH

      cmdsize 88

         path @loader_path/../UE4/Engine/Binaries/ThirdParty/OpenVR/OpenVRv1_5_17/osx32 (offset 12)

--

          cmd LC_RPATH

      cmdsize 72

         path @loader_path/../UE4/Engine/Binaries/ThirdParty/Ogg/Mac (offset 12)

--

          cmd LC_RPATH

      cmdsize 72

         path @loader_path/../UE4/Engine/Binaries/ThirdParty/Vorbis/Mac (offset 12)

```

I’d expect there be an rpath that points to the library inside the app bundle, game.app (and I can verify that the library has been copied inside the app bundle properly).

How can I fix RPATH for thirdparty dependencies?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5a7a8c01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5a7a8c01](https://forums.unrealengine.com/u/anonymous_user_5a7a8c01)\
**Post date:** [January 24, 2020, 8:40pm UTC](https://forums.unrealengine.com/t/packaging-for-macos-doesnt-add-correct-rpath-for-thirdparty-dependencies/136944/2 "2020-01-24T20:40:34Z")

</div>

I wrote a patch for UnrealBuildSystem that fixes RPATHs automatically, if the library is from “Plugins”. Since I can’t share the forked repo of UnrealEngine (it’s private), here is the patch:

```auto

diff --git a/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs b/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
index f1781826290..f96a5b938ff 100644
--- a/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
+++ b/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
@@ -643,6 +643,20 @@ namespace UnrealBuildTool
                     string BundleRelativeDir = Utils.MakePathRelativeTo(BundleLibraryDir, ExeDir).Replace("\\", "/");
                     LinkCommand += " -rpath \"@loader_path/" + BundleRelativeDir + "\"";

+ if (LibraryFullPath.Contains("Plugins") || LibraryFullPath.Contains("ThirdParty"))
+ {
+ string ProjectDir = Path.GetDirectoryName(ProjectFile.ToString());
+ string GameName = Path.GetFileName(ExeAbsolutePath);
+ string BundleGameDir = Path.GetFullPath(BundleUE4Dir + "/" + GameName);
+ string PackagedLibPath = BundleGameDir + LibraryDir.Replace(ProjectDir, "");
+ string PackagedLibRpath = Utils.MakePathRelativeTo(PackagedLibPath, ExeDir).Replace("\\", "/");
+
+ LinkCommand += " -rpath \"@executable_path/" + PackagedLibRpath + "\"";
+
+ Log.TraceInformation("Fixing library RPATH for app bundle: {0} -> @executable_path/{1}", 
+ PackagedLibPath, PackagedLibRpath);
+ }
+
                     // For staged code-based games we need additional entry if the game is not stored directly in the engine's root directory
                     if (bCanUseMultipleRPATHs)
                     {

```

You will then need to open the “UnrealBuildTool.sln” VS solution in “Engine/Source/Programs/UnrealBuildTool” and re-compile it.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cd6447761](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cd6447761](https://forums.unrealengine.com/u/anonymous_user_cd6447761)\
**Post date:** [December 30, 2020, 1:03pm UTC](https://forums.unrealengine.com/t/packaging-for-macos-doesnt-add-correct-rpath-for-thirdparty-dependencies/136944/3 "2020-12-30T13:03:11Z")

</div>

I followed your steps, but I do not know where exactly should your code go in the UnrealBuildTool.sln.
