Build binaries from source

Hello,

I am trying to build binaries(lib and dll) from source using cmake command line.
Refering - OpenCV: Installation in Windows,
i can see that the cmake options are for installOCV.sh.

File installOCV.sh will not work under windows platform.

Please advice…

ignore that. it’s outdated and not well written. especially that shell script.

basically:

  • pick a directory to keep opencv’s source and binaries in. let’s call it $base (“P:” in my case)
  • git clone opencv and opencv_contrib into that directory (each into a separate directory). you get $base\opencv and $base\opencv_contrib
  • image
  • run cmake-gui, set those things (red means changed, does not mean error)
  • image
  • press “configure”
  • image
  • watch what it’s saying
  • browse the now populated variables, disable or enable some things (go by that installOCV.sh file’s CMAKE_OPTIONS if you like)
  • change things and rerun “configure” until you are satisfied and until cmake is satisfied (it will complain if there’s trouble)
  • click “generate”. it’ll ask you to pick a generator. you probably want VS 16 (2019). it’ll generate the build files now.

Hello Sir,

Thank you very much for your reply.
I followed the steps. And got the error. Attached the screen shot.

Regards

Naushad. C. K.

(Attachment Cmake error.docx is missing)

post all the logs that cmake gives you. a simple screenshot has no use.

Unable to add/insert other than images…

CMakeError.log

Compiling the CXX compiler identification source file “CMakeCXXCompilerId.cpp” failed.
Compiler:
Build flags:
Id flags:

The output was:
1
Microsoft ® Build Engine version 14.0.25420.1
Copyright © Microsoft Corporation. All rights reserved.

Build started 14-Dec-20 1:18:29 PM.
Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj” on node 1 (default targets).
PrepareForBuild:
Creating directory “Debug”.
Creating directory “Debug\CompilerIdCXX.tlog”.
InitializeBuildStatus:
Creating “Debug\CompilerIdCXX.tlog\unsuccessfulbuild” because “AlwaysCreate” was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:queue CMakeCXXCompilerId.cpp
CMakeCXXCompilerId.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdCXX.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /manifest:embed /PDB:".\CompilerIdCXX.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdCXX.lib" /MACHINE:X86 /SAFESEH Debug\CMakeCXXCompilerId.obj
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj” (default targets) – FAILED.

Build FAILED.

“C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj” (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:03.08

Compiling the CXX compiler identification source file “CMakeCXXCompilerId.cpp” failed.
Compiler:
Build flags:
Id flags:

The output was:
1
Microsoft ® Build Engine version 14.0.25420.1
Copyright © Microsoft Corporation. All rights reserved.

Build started 14-Dec-20 1:18:33 PM.
Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj” on node 1 (default targets).
PrepareForBuild:
Creating directory “Debug”.
Creating directory “Debug\CompilerIdCXX.tlog”.
InitializeBuildStatus:
Creating “Debug\CompilerIdCXX.tlog\unsuccessfulbuild” because “AlwaysCreate” was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:queue CMakeCXXCompilerId.cpp
CMakeCXXCompilerId.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdCXX.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /manifest:embed /PDB:".\CompilerIdCXX.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdCXX.lib" /MACHINE:X86 /SAFESEH Debug\CMakeCXXCompilerId.obj
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj” (default targets) – FAILED.

Build FAILED.

“C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj” (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdCXX\CompilerIdCXX.vcxproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:01.99

Compiling the C compiler identification source file “CMakeCCompilerId.c” failed.
Compiler:
Build flags:
Id flags:

The output was:
1
Microsoft ® Build Engine version 14.0.25420.1
Copyright © Microsoft Corporation. All rights reserved.

Build started 14-Dec-20 1:18:36 PM.
Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj” on node 1 (default targets).
PrepareForBuild:
Creating directory “Debug”.
Creating directory “Debug\CompilerIdC.tlog”.
InitializeBuildStatus:
Creating “Debug\CompilerIdC.tlog\unsuccessfulbuild” because “AlwaysCreate” was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\" /Fd"Debug\vc140.pdb" /Gd /TC /analyze- /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdC.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /manifest:embed /PDB:".\CompilerIdC.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdC.lib" /MACHINE:X86 /SAFESEH Debug\CMakeCCompilerId.obj
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj” (default targets) – FAILED.

Build FAILED.

“C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj” (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:02.15

Compiling the C compiler identification source file “CMakeCCompilerId.c” failed.
Compiler:
Build flags:
Id flags:

The output was:
1
Microsoft ® Build Engine version 14.0.25420.1
Copyright © Microsoft Corporation. All rights reserved.

Build started 14-Dec-20 1:18:38 PM.
Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj” on node 1 (default targets).
PrepareForBuild:
Creating directory “Debug”.
Creating directory “Debug\CompilerIdC.tlog”.
InitializeBuildStatus:
Creating “Debug\CompilerIdC.tlog\unsuccessfulbuild” because “AlwaysCreate” was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\" /Fd"Debug\vc140.pdb" /Gd /TC /analyze- /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdC.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /manifest:embed /PDB:".\CompilerIdC.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdC.lib" /MACHINE:X86 /SAFESEH Debug\CMakeCCompilerId.obj
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project “C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj” (default targets) – FAILED.

Build FAILED.

“C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj” (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’ [C:\Opencv\opencv\build2\CMakeFiles\3.18.0\CompilerIdC\CompilerIdC.vcxproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:01.20

Have you tried building from the command line? Its easier because then we can see your input to cmake as well as the errors. With VS2019 I would first try to compile without any extra modules apart from contrib with the following

set "openCvSource=PATH_TO_OPENCV_SOURCE"
set "openCVExtraModules=PATH_TO_OPENCV_CONTRIB_MODULES"
set "openCvBuild=%openCvSource%\build"
set "generator=Visual Studio 16 2019"
"C:\Program Files\CMake\bin\cmake.exe" -B"%openCvBuild%/" -H"%openCvSource%/" -G"%generator%" -DOPENCV_EXTRA_MODULES_PATH="%openCVExtraModules%/" ^
-DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON ^
-DBUILD_opencv_world=ON 

Yes, i have tried to build from command line. Update is given below.

  1. Using visual studio 2013 via command line or gui.

    This executes and completes without generating lib files.

  2. Using visual studio 2015 via command line or gui.

    Fails with error(compiler error).

By checking the logs, says the “ucrtd.dll” error.

After so much checking.searching, found the following.
From VS 2015, From VS 2015 addutional requirement is added.
It is - Windows SDK must be installed.
It would be under - C:\Program Files (x86)\Windows Kits\10\Lib

CMake build error with VS 2015

Issue - ucrt.dll not found by VS 2015 compile/Link

Reason - ucrt is not in the VC directories path.

Temp. solution - Copied the following files from
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x86
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64
to
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib
ucrt.lib
ucrtd.lib

After the steps the cmake started to work. But STILL THE BINARIES ARE NOT CREATING.

Any solution…

I understand it may not be possible but have you tried with a more recent version of VS?

Its been a long time since I used VS2015 for OpenCV (last version was 3.3), have you tried installing windows SDK 8.1 as well?
vs2015_sdk_opts

Probably a stupid question but did you install the C++ components when you installed VS?

If possible can you post the input to CMake, and the build config which it outputs before you build.