Error loading a library for Mac universal build: "logic needs to be updated"

I’m building a UE5.3 application using UAT BuildCookRun. For Mac, when I try to build a universal binary per the documentation: -specifiedarchitecture=arm64+x86_6 I get the following build error when a module loads a precompiled library:

Unable to instantiate module 'CSpice_Library': Asking CppCompileEnvironment for a single Architecture, but it has multiple Architectures (arm64, x64). This indicates logic needs to be updated

I see what it’s getting at but I can’t find any reference to this error or how I would configure the build for this. I have both x86_64 and arm64 versions of the library at lib/Mac/cspice.a and lib/Mac/arm/cspice.a respectively. Here is how the library is selected in its Build.cs:

public class CSpice_Library : ModuleRules
{
    public CSpice_Library(ReadOnlyTargetRules Target) : base(Target)
    {
        string libFile = CSpiceLibPath(Target);
        ...
    }
    static public string CSpiceLibPath(ReadOnlyTargetRules targetRules)
    {
        string relativePathToCSpiceLib = RelativePathToCSpiceLibraries + targetRules.Platform.ToString();
        string libName = "/cspice.lib";
        
        if (targetRules.Platform == UnrealTargetPlatform.Mac)
        {
            libName = "/cspice.a";
            if (targetRules.Architecture == UnrealArch.Arm64)
            {
                relativePathToCSpiceLib += "/arm";
            }
        }
        ...
        relativePathToCSpiceLib += libName;

        return Path.Combine(targetRules.ProjectFile.Directory.FullName, relativePathToCSpiceLib);
    }

This all checks out, but I don’t know how this relates to “asking CppCompileEnvironment for a single architecture”. Is this the logic in question, and how do you configure multiple versions of a library for a universal build?

Could you find a solution? I’m having the exact same issue when trying to submit a plugin to the Unreal Marketplace: they tell me I need to fix the plugin because it generates the error "Unable to instantiate module ‘YourPlugin’: Asking CppCompileEnvironment for a single Architecture, but it has multiple Architectures (arm64, x64). This indicates logic needs to be updated.
The strange thing is that they only complain about this for UE 5.4, all previous versions of the Engine apparently work just fine with the exact same .uplugin and .build.cs files.

It happens when you call Target.Architecture when building for multiple architectures. An exception is thrown when calling the Architecture getter in your Build.cs.

To check for a single architecture, use Target.Architectures (notice the s) instead.

if (Target.Architectures.Contains(UnrealArch.Arm64))
{
    // ARM64, but it can also be x64!
}

The reason it happens from 5.4 is because the Marketplace now builds code plugins for Android arm64+x64 instead of only arm64.

2 Likes

Thank you so much! After weeks of trying, this finally solved the issue for me.

Thank you @Amneri I ultimately had to rewrite the whole function to allow it to add multiple paths, but this was the missing piece.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.