Download

how to add C++ macro definition

Even I add Macro Definition in file MyProject.Target.cs


public override void SetupGlobalEnvironment(  
        TargetInfo Target,  
        ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,  
        ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration  
        )  
{  
    OutCPPEnvironmentConfiguration.Definitions.Add("_CRT_SECURE_NO_WARNINGS");  
}

visual studio also shows warning:
8e2a0f1953ac14772307ae18797a56a1d16cf455.png

how to add Definition in UE4 project?

can anybody help to resolve this problem?

I don’t know the answer to your question; I would tend to avoid strcpy() instead :slight_smile: There must be a better way…

Simply put this before the include and try this : #define _CRT_SECURE_NO_WARNINGS 1

if not work try other methods :
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

Hope that help you.

thx~, but if define macro in code, it’s not convenient build for other platform.

thx~, but if define macro in code, it’s not convenient build for other platform.

I found the solution for latest UE4 version, define your macros in the constructor of MyProject.Build.cs ,like this:


using UnrealBuildTool;

public class MyProj : ModuleRules
{
    public MyProj(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Slate", "SlateCore" });
        PrivateDependencyModuleNames.AddRange(new string] { });


        Definitions.Add("_CRT_SECURE_NO_WARNINGS");
}
}

also can see example here:
https://github.com/monsieurgustav/UE4-OSC/blob/master/OSC/Source/OSC/OSC.Build.cs

This tbh, you shouldn’t be using unsafe string copying methods like that unless you’re willing to deal with the potential buffer overrun problems that naturally come from it. Is there also a reason why you’re using the C string functions instead of using Unreal’s FString?

becase I use a third lib which contains strcpy(), if avoid to use strcpy, I have to modify it’s code.

Thank you so much for sharing this. I got these warnings just by including Steam’s SDK and all those warnings polluting my squeaky-clean output window were driving me nuts :slight_smile: