올해 2월에 조립 PC를 새로 장만해서 Visual Studio 2015를 깔았고, 이후 Visual Studio 2017 버전이 나와서 Visual Studio 2015를 지우고 Visual Studio 2017만 사용하려고 했었습니다. 그런데 nVidia Cuda가 Visual Studio 2017을 아직 지원하지 않아서 다시 Visual Studio 2015를 설치를 했습니다. 그리고나서 OpenCV 최신 소스를 Visual Studio 2015로 새로 빌드하려고 CMake에서 "Visual Studio 14 2015 Win64"를 선택했는데, 이상한 에러가 발생하네요.



The CXX compiler identification is unknown
The C compiler identification is unknown


일단 눈으로 보이는 에러 메시지는 CXX, C 컴파일러를 찾지 못한다는 것인데요, 자세한 내용을 확인하기 위해 C:/opencv/mybuild/CMakeFiles/CMakeOutput.log 파일을 열어보았습니다.


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

The output was:
1
Microsoft (R) Build Engine 버전 14.0.25420.1]
Copyright (C) Microsoft Corporation. All rights reserved.

빌드 시작: 2017-08-03 오전 10:47:35
1 노드의 "C:\opencv\mybuild\CMakeFiles\3.9.0\CompilerIdCXX\CompilerIdCXX.vcxproj" 프로젝트(기본 대상)입니다.
PrepareForBuild:
  "Debug\" 디렉터리를 만들고 있습니다.
  "Debug\CompilerIdCXX.tlog\" 디렉터리를 만들고 있습니다.
InitializeBuildStatus:
  "AlwaysCreate"이(가) 지정되었기 때문에 "Debug\CompilerIdCXX.tlog\unsuccessfulbuild"을(를) 만들고 있습니다.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /c /nologo /W0 /WX- /Od /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /errorReport:queue CMakeCXXCompilerId.cpp
  CMakeCXXCompilerId.cpp
Link:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\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:X64 Debug\CMakeCXXCompilerId.obj
LINK : fatal error LNK1158: 'rc.exe'을(를) 실행할 수 없습니다. [C:\opencv\mybuild\CMakeFiles\3.9.0\CompilerIdCXX\CompilerIdCXX.vcxproj]
"C:\opencv\mybuild\CMakeFiles\3.9.0\CompilerIdCXX\CompilerIdCXX.vcxproj" 프로젝트를 빌드했습니다(기본 대상). - 실패

빌드하지 못했습니다.

"C:\opencv\mybuild\CMakeFiles\3.9.0\CompilerIdCXX\CompilerIdCXX.vcxproj"(기본 대상)(1)->
(Link 대상) ->
  LINK : fatal error LNK1158: 'rc.exe'을(를) 실행할 수 없습니다. [C:\opencv\mybuild\CMakeFiles\3.9.0\CompilerIdCXX\CompilerIdCXX.vcxproj]

    경고 0개
    오류 1개

경과 시간: 00:00:00.81

...


중간에 보면 rc.exe 를 실행할 수 없다는 메시지가 나타납니다. rc.exe는 "Microsoft (R) Windows (R) Resource Compiler"를 의미하는 것인데, 이 파일을 찾을 수 없다는 의미인거네요. 시작 메뉴에서 "Visual Studio 2015 Tools 명령 프롬프트 열기" 메뉴를 찾아서 실행하고, 나타난 도스창에서 rc.exe를 입력하면 실제로도 해당 파일을 찾을 수 없다고 나타납니다.


이와 반대로 "Open Visual Studio 2017 Tools Command Prompt" 커맨드 창에서는 rc.exe /? 명령을 실행하면 아래와 같이 프로그램이 잘 실행됩니다.


결국 원인을 알 수 없는 이유로 인하여 Visual Studio 2015 환경에서는 rc.exe 파일을 찾지 못한다는 것이고, 이는 기본적으로 Visual Studio 2017 커맨드창 환경과 Visual Studio 2015 커맨드창의 PATH 설정이 다르기 때문일 것입니다. 그래서 두 창에서 각각 PATH 명령을 입력해서 그 차이를 비교해보고, 실제 rc.exe 파일이 있는 위치를 검토해보니 아래 디렉토리가 PATH에 있느냐 없느냐의 차이인 것으로 보였습니다.


C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86


바로 이 폴더에 Windows SDK 버전 10의 rc.exe 파일이 있네요. 그러므로 Visual Studio 2015 버전에서도 이 디렉토리를 PATH 환경 변수에 추가해주면 되는데요, 음.. 반대로 위 폴더에 있는 rc.exe 파일을 Visual Studio 2015 커맨드창 PATH 경로에 복사해주어도 정상적으로 동작을 합니다. 그래서 해결책은 이렇습니다.


1. C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86 폴더에서

2. rc.exe 파일과 rcdll.dll 파일을 복사해서

3. C:\Program Files (x86)\Windows Kits\10\bin\x86\ 폴더에 붙여넣습니다.


그랬더니 CMake가 잘 동작을 하네요~ :-)



Posted by kkokkal
: