Hello
I’m trying to add OpenCV to UE4 project.
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.IO;
public class thirdPerson4_8 : ModuleRules
{
private string ModulePath
{
get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); }
}
private string ThirdPartyPath
{
get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
}
public thirdPerson4_8(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string] { });
LoadOpenCV(Target);
}
public bool LoadOpenCV(TargetInfo Target)
{
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 if (Target.Platform == UnrealTargetPlatform.Win32)
{
LibPath = Path.Combine(OpenCVPath, "Libraries", "Win32");
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 Library Path
//PublicLibraryPaths.Add(LibPath);
// Add Dependencies
if (!isdebug)
{
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_calib3d2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_contrib2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_core2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_features2d2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_flann2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_gpu2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_highgui2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_imgproc2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_legacy2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ml2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_nonfree2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_objdetect2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ocl2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_photo2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_stitching2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_superres2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ts2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_video2410.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_videostab2410.lib"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_calib3d2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_contrib2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_core2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_features2d2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_flann2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_gpu2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_highgui2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_imgproc2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_legacy2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ml2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_nonfree2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_objdetect2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ocl2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_photo2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_stitching2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_superres2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ts2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_video2410.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_videostab2410.dll"));
}
else
{
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_calib3d2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_calib3d2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_contrib2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_core2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_features2d2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_flann2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_gpu2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_highgui2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_imgproc2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_legacy2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ml2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_nonfree2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_objdetect2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ocl2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_photo2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_stitching2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_superres2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ts2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_video2410d.lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_videostab2410d.lib"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_calib3d2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_contrib2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_core2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_features2d2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_flann2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_gpu2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_highgui2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_imgproc2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_legacy2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ml2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_nonfree2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_objdetect2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ocl2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_photo2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_stitching2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_superres2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ts2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_video2410d.dll"));
PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_videostab2410d.dll"));
}
PublicIncludePaths.Add(Path.Combine(OpenCVPath, "Includes"));
}
Definitions.Add(string.Format("WITH_OPENCV_BINDING={0}", isLibrarySupported ? 1 : 0));
return isLibrarySupported;
}
}
After build i get many LNK2038 errors:
Error 7 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(alloc.obj) thirdPerson4_8
Error 8 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(matrix.obj) thirdPerson4_8
Error 9 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(system.obj) thirdPerson4_8
Error 10 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(opencv_core_pch.obj) thirdPerson4_8
Error 11 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(copy.obj) thirdPerson4_8
Error 12 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(convert.obj) thirdPerson4_8
Error 13 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(stat.obj) thirdPerson4_8
Error 14 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in thirdPerson4_8.h.obj C:\Users\hompain\Documents\Unreal Projects hirdPerson4_8\Intermediate\ProjectFiles\opencv_core2410.lib(rand.obj) thirdPerson4_8
.
.
.
I tried to change the actual engine variable in BuildConfiguration.cs. <bDebugBuildsActuallyUseDebugCRT>true</bDebugBuildsActuallyUseDebugCRT>
From this thread https://forums.unrealengine.com/showthread.php?63340-Building-engine-with-Debug-Runtime-library
But this did not help.
What am i doing wrong?