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
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 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);
}
}
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
}
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.