Unreal Build Tool error

Good day, have some errors with UBT when try add OpenCV to project. Can somebody explain me probable reasons?

error CS1729: ‘UnrealBuildTool.ModuleRules’ does not contain a constructor that takes 0 arguments QuestTest D:\Work\VRPal\UEProj\QuestTest\Intermediate\ProjectFiles\UnrealBuildTool 1

error CS0122: ‘UnrealBuildTool.BuildConfiguration’ is inaccessible due to its protection level QuestTest D:\Work\VRPal\UEProj\QuestTest\Intermediate\ProjectFiles\UnrealBuildTool 1

Did you upgrade your project from some older version of the engine?

yes, but i create another project on 4.19, this result repeated.

I see. Could you show content of your ProjectName.Build.cs file?

Well here are the error code docs
cs1729: Compiler Error CS1729 | Microsoft Docs

cs0122 Compiler Error CS0122 | Microsoft Docs

the first error seams like some c++ object you made doesn’t have a constructor.
see the rule of 3/5/0 http://en.cppreference.com/w/cpp/language/rule_of_three

I am thinking that the location to which things need to be compiled (the project location) might have its permissions on say read only - or your user (window’s user) might not have permission to the file.

public class CPlusPlus : ModuleRules
{
private string ModulePath
{
get { return ModuleDirectory; }
}

private string ThirdPartyPath
{
    get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../ThirdParty/")); }
}

public bool LoadOpenCV(TargetInfo Target)
{
    // Start OpenCV linking here!
    bool isLibrarySupported = false;

    // Create OpenCV Path 
    string OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV");

    // Get Library Path 
    string LibPath = "";
    bool isdebug = Target.Configuration == UnrealTargetConfiguration.Debug && BuildConfiguration.bDebugBuildsActuallyUseDebugCRT;
    if (Target.Platform == UnrealTargetPlatform.Win64)
    {
        LibPath = Path.Combine(OpenCVPath, "Libraries", "Win64");
        isLibrarySupported = true;
    }
    else
    {
        string Err = string.Format("{0} dedicated server is made to depend on {1}. We want to avoid this, please correct module dependencies.", Target.Platform.ToString(), this.ToString()); System.Console.WriteLine(Err);
    }

    if (isLibrarySupported)
    {
        //Add Include path 
        PublicIncludePaths.AddRange(new string[] { Path.Combine(OpenCVPath, "Includes") });

        // Add Library Path 
        PublicLibraryPaths.Add(LibPath);

        //Add Static Libraries
        PublicAdditionalLibraries.Add("opencv_world320.lib");

        //Add Dynamic Libraries
        PublicDelayLoadDLLs.Add("opencv_world320.dll");
        PublicDelayLoadDLLs.Add("opencv_ffmpeg320_64.dll");
    }

    Definitions.Add(string.Format("WITH_OPENCV_BINDING={0}", isLibrarySupported ? 1 : 0));

    return isLibrarySupported;
}

Some interesting, that i use tutorial for OpenCV and not work.

public CPlusPlus(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RHI", "RenderCore", "ShaderCore" });

		PrivateDependencyModuleNames.AddRange(new string[] {  });

        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
       // LoadOpenCV(Target);
	}

}

And this is not C++ compiler.

Is this the only module you have in your project? QuestTest perhaps? It looks error is related to that module

some edit

public QuestTest(TargetInfo Target)

UBT not see - BuildConfiguration.bDebugBuildsActuallyUseDebugCRT and constructor for game. I try connect OpenCV to UE4.

I think you might be missing call to base constructor in constructor of your QuestTest module class (within QuestTest .Build.cs).

What’s the parent of that class?

Do you mean game constructor with initializtion game modules or C# constructor for build script?

C# constructor.

#include “QuestTest.h”
#include “Modules/ModuleManager.h”

IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, QuestTest, "QuestTest" );

I meant constructor within QuestTest.Build.cs, sorry for not specifying that. :stuck_out_tongue:

//Constructor dependencies
public QuestTest(TargetInfo Target)//(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RHI", "RenderCore", "ShaderCore" });

		//PrivateDependencyModuleNames.AddRange(new string[] {  });

        LoadOpenCV(Target);

        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
    }

It’s constructor in *.Build.cs

From what I know, in UE 4.16 engine switched from using ReadOnlyTargetRules from TargetInfo in constructor of your C# modules. In newer version you also have to call base contructor and pass that target(ReadOnlyTargetRules) there.

So, here’s modified code of yours that should work:

Constructor:

// Constructor dependencies
public QuestTest(ReadOnlyTargetRules Target) : base(Target) // changed
{
	PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

	PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RHI", "RenderCore", "ShaderCore" });

	//PrivateDependencyModuleNames.AddRange(new string[] {  });

	LoadOpenCV(Target);

	// Uncomment if you are using Slate UI
	// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

	// Uncomment if you are using online features
	// PrivateDependencyModuleNames.Add("OnlineSubsystem");

	// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}

And LoadOpenCS function:

public bool LoadOpenCV(ReadOnlyTargetRules Target)  // changed
{
	// Start OpenCV linking here!
	bool isLibrarySupported = false;

	// Create OpenCV Path 
	string OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV");

	// Get Library Path 
	string LibPath = "";
	bool isdebug = Target.Configuration == UnrealTargetConfiguration.Debug && Target.bDebugBuildsActuallyUseDebugCRT;  // changed
	if (Target.Platform == UnrealTargetPlatform.Win64)
	{
		LibPath = Path.Combine(OpenCVPath, "Libraries", "Win64");
		isLibrarySupported = true;
	}
	else
	{
		string Err = string.Format("{0} dedicated server is made to depend on {1}. We want to avoid this, please correct module dependencies.", Target.Platform.ToString(), this.ToString()); System.Console.WriteLine(Err);
	}

	if (isLibrarySupported)
	{
		//Add Include path 
		PublicIncludePaths.AddRange(new string[] { Path.Combine(OpenCVPath, "Includes") });

		// Add Library Path 
		PublicLibraryPaths.Add(LibPath);

		//Add Static Libraries
		PublicAdditionalLibraries.Add("opencv_world320.lib");

		//Add Dynamic Libraries
		PublicDelayLoadDLLs.Add("opencv_world320.dll");
		PublicDelayLoadDLLs.Add("opencv_ffmpeg320_64.dll");
	}

	Definitions.Add(string.Format("WITH_OPENCV_BINDING={0}", isLibrarySupported ? 1 : 0));

	return isLibrarySupported;
}

In case you’d wonder, changed lines (3) are marked with // changed comment.
Hope this helps.

1 Like