Project fails to load because of the plugin with third party library (macOS)

I have a plugin which uses thirdparty library. The project builds in Xcode but Editor fails to open it with this error:

Plugin ‘MyPlugin’ failed to load because module ‘MyModule’ could not be loaded. There may be an operating system error or the module may not be properly set up.

Not very informative, but I located the exact error by using macOS Console.app (in ~/Library/Logs -> Unreal Engine -> MyProjectEditor -> MyProject.log):



[2020.01.13-22.44.37:369]  0]LogMac: Warning: dlopen failed: dlopen(<...>/MyProject/Plugins/MyPlugin/Binaries/Mac/UE4Editor-MyPlugin.dylib, 5): Library not loaded: @rpath/libmylib.dylib
  Referenced from: <...>/MyProject/Plugins/MyPlugin/Binaries/Mac/UE4Editor-MyPlugin.dylib
  Reason: image not found
[2020.01.13-22.44.37:369]  0]LogModuleManager: Warning: ModuleManager: Unable to load module '<...>/MyProject/Plugins/opt/Binaries/Mac/UE4Editor-MyPlugin.dylib' because the file couldn't be loaded by the OS.


From the otool output:



$ otool -L <...>/MyProject/Plugins/MyPlugin/Binaries/Mac/UE4Editor-MyPlugin.dylib
<...>/MyProject/Plugins/MyPlugin/Binaries/Mac/UE4Editor-MyPlugin-0004.dylib:

@rpath/UE4Editor-MyPlugin-0004.dylib (compatibility version 4.23.0, current version 838.65.87)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)
/System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/A/MultitouchSupport (compatibility version 1.0.0, current version 3410.2.0)
@rpath/libmylib.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 162.0.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 59306.41.2)
@rpath/UE4Editor-Core.dylib (compatibility version 4.23.0, current version 838.65.87)
@rpath/UE4Editor-Projects.dylib (compatibility version 4.23.0, current version 838.65.87)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)


…I see dependency on libmylib.dylib, and it is supposed to load from rpath which makes sense, however when I build project in Xcode I never see this library being copied anywhere.
I’m unsure why it’s not being copied.
Here’s my MyPlugin.Build.cs:



using UnrealBuildTool;

public class opt : ModuleRules
{
public opt(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(
new string]
{
     "Core",
     "depsLibrary",
     "Projects"
}
);

        bUseRTTI = true;
        bEnableExceptions = true;
}
}


and depsLibrary.Build.cs:



using System.IO;
using UnrealBuildTool;
using System;

public class depsLibrary : ModuleRules
{

public depsLibrary(ReadOnlyTargetRules Target) : base(Target)
{
Type = ModuleType.External;
        LoadThirdPartyLibs();
}

    private string ModulePath
    {
        get {
            return ModuleDirectory;
        }
    }

    public void LoadThirdPartyLibs()
    {
        PublicIncludePaths.Add(Path.Combine(ModulePath, "mylib", "include"));
        PublicIncludePaths.Add(Path.Combine(ModulePath, "boost", "include"));

        if (Target.Platform == UnrealTargetPlatform.Android)
        {
            // set up Android lib paths
        }
        else if (Target.Platform == UnrealTargetPlatform.IOS)
        {
            // set up iOS lib paths
        }
        else if (Target.Platform == UnrealTargetPlatform.Mac)
        {
            // set up macOS lib paths
            string libPath = Path.Combine(ModulePath, "mylib", "lib");

            PublicLibraryPaths.Add(libPath);
            PublicAdditionalLibraries.Add(Path.Combine(libPath, "libmylib.dylib"));
            RuntimeDependencies.Add(Path.Combine(libPath, "libmylib.dylib"));
        }

        bUseRTTI = true;
        bEnableExceptions = true;
    }
}


How can I resolve this issue?
Also, I don’t need plugin to run in Editor (only game runtime is needed).

For people searching this error like me, I had a module load issue today on mac and the logs no longer includes the detail of dlopen errors :frowning: (macOS Ventura 13.6.7, UE 5.4). Unless there’s something to configure on the mac?
I tried launching with the env var DYLD_PRINT_LIBRARIES=ON, but it doesn’t list the errors either…
So I had to “jump through the hoops” like Iktomi in Dlopen failure with OnlineSubsystemNull on Mac UE-5.0 Source Build

I am also having this issue. When I click “install to engine” on the epic launcher, nothing happens. And then I try to open my project and it says that it can’t run without that plugin.