Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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):

    Code:
    [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:

    Code:
    $ 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:

    Code:
    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:

    Code:
    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).
Working...
X