1 错误原因

出现这种错误,一般为Windows中的宏与UE4冲突所导致。

2 解决方法

2.1 修改插件xxxx.Build.cs

在插件xxxx.Build.cs中加入以下代码:

bEnableUndefinedIdentifierWarnings = false;

完整插件xxxx.Build.cs代码示例:

// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class TwowaySocketPlugin : ModuleRules
{
    public TwowaySocketPlugin(ReadOnlyTargetRules Target) : base(Target)
    {
        bEnableUndefinedIdentifierWarnings = false;

        PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicIncludePaths.AddRange(
            new string[] {
                // ... add public include paths required here ...
            }
            );


        PrivateIncludePaths.AddRange(
            new string[] {
                // ... add other private include paths required here ...
            }
            );


        PublicDependencyModuleNames.AddRange(
            new string[]
            {
                "Core",
                // ... add other public dependencies that you statically link with here ...
            }
            );


        PrivateDependencyModuleNames.AddRange(
            new string[]
            {
                "CoreUObject",
                "Engine",
                "Slate",
                "SlateCore",
                // ... add private dependencies that you statically link with here ...  
            }
            );


        DynamicallyLoadedModuleNames.AddRange(
            new string[]
            {
                // ... add any modules that your module loads dynamically here ...
            }
            );
    }
}

2.2 使用UE4包含机制解决

使用以下代码包含起冲突的Windows相关的头文件:

#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/PreWindowsApi.h"

// 包含起冲突的头文件,例如
#include <windows.h>

#include "Windows/PostWindowsApi.h"
#include "Windows/HideWindowsPlatformTypes.h"