Winodws10 VS2019 Clion CMake 编译 OpenCV rc 系统找不到指定的文件。NMAKE : fatal error U1077

在从源码编译开源库这条路上,怎么这么多坑给我踩?

这次是编译 OpenCV


简单总结

在 Windows10 系统下,使用 VS2019 编译链,在 Clion 编译 OpenCV 时,出现报错,报错的关键信息:

Detecting C compiler ABI info - failed
 rc 系统找不到指定的文件。NMAKE : fatal error U1077

解决方案

指定 CMake 编译的目标平台/架构(platform/architecture),指定方式:

cmake -G "Visual Studio 16 2019" -A Win32

cmake -G "Visual Studio 16 2019" -A x64

cmake -G "Visual Studio 16 2019" -A ARM

cmake -G "Visual Studio 16 2019" -A ARM64

痛苦回顾


来看看咱的报错信息
Winodws10 VS2019 Clion CMake 编译 OpenCV rc 系统找不到指定的文件。NMAKE : fatal error U1077_第1张图片


Microsoft Windows [版本 10.0.19043.1320]
(c) Microsoft Corporation。保留所有权利。

C:\Workspace\CLion\opencv_next_test>cd build

C:\Workspace\CLion\opencv_next_test\build>"C:\Software\JetBrains\CLion 2021.1.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEPENDS_USE_COMPILER=FALSE  -G "CodeBlocks - NMake Makefiles" ../
-- The C compiler identification is MSVC 19.29.30136.0
-- The CXX compiler identification is MSVC 19.29.30136.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Software/JetBrains/CLion 2021.1.1/bin/cmake/win/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Workspace/CLion/opencv_next_test/build/CMakeFiles/CMakeTmp

    Run Build Command(s):nmake -f Makefile /nologo cmTC_f9517\fast &&   "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_f9517.dir\build.make /nologo -L                  CMakeFiles\cmTC_f9517.dir\build
    Building C object CMakeFiles/cmTC_f9517.dir/testCCompiler.c.obj
        "C:\Software\JetBrains\CLion 2021.1.1\bin\cmake\win\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_f9517.dir\testCCompiler.c.obj.d --working-dir=C:\Workspace\CLion\opencv_next_test\build\CMakeFiles\CMakeTmp --filter-prefix="" -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe @C:\Users\ruan\AppData\Local\Temp\nm6CB6.tmp
    Linking C executable cmTC_f9517.exe
        "C:\Software\JetBrains\CLion 2021.1.1\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_f9517.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_f9517.dir\objects1.rsp @C:\Users\ruan\AppData\Local\Temp\nm6D92.tmp
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_f9517.dir/manifest.res CMakeFiles\cmTC_f9517.dir/manifest.rc" failed (exit code 0) with the following output:
    系统找不到指定的文件。NMAKE : fatal error U1077: “"C:\Software\JetBrains\CLion 2021.1.1\bin\cmake\win\bin\cmake.exe"”: 返回代码“0xffffffff”
    Stop.
    NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\nmake.exe"”: 返回代码“0x2”
    Stop.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Workspace/CLion/opencv_next_test/build/CMakeFiles/CMakeOutput.log".
See also "C:/Workspace/CLion/opencv_next_test/build/CMakeFiles/CMakeError.log".

C:\Workspace\CLion\opencv_next_test\build>

关键是
Detecting C compiler ABI info - failed

rc 系统找不到指定的文件。NMAKE : fatal error U1077


根据jetbrains的说法,这不是他们的锅。


无论是在命令行还是在Clion里面都这样,但是好奇的是在 Visual Studio 2019 里面却没事?


然后,确实找不到 rc

C:\Workspace\CLion\opencv_next_test\build>where rc.exe
信息: 用提供的模式无法找到文件。

难道是 VS2019 里面有一些配置好的环境变量?


通过查找网上一堆 rc 和无法确定编译器的问题

  1. Error: The C compiler is not able to compile a simple test program.

  2. rc.exe no longer found in VS 2015 Command Prompt

  3. Windows compilation error: Missing rc.exe


然鹅他们都不起作用,就算能找到rc,也会说找不到某些头文件。


停下来理一下思路,OpenCV编译失败,因为没有成功检测编译器的信息,原因是检测时找不到rc发生了中断。

那会不会是某些编译参数影响了呢?排查了一下,发现用下面这个参数编译就会出问题

cmake -G "CodeBlocks - NMake Makefiles" ../

好,VS2019用的应该是Visual Studio 16 2019,那就改一下呗。


根据 CMake 的 文档,改成

cmake -G "Visual Studio 16 2019"  ../

成功了~

补一张 CLion 设置 CMake 参数的图

Winodws10 VS2019 Clion CMake 编译 OpenCV rc 系统找不到指定的文件。NMAKE : fatal error U1077_第2张图片


CLion --> File --> Settings --> Build,Execution,Deployment --> CMake --> Release/Debug --> CMake options
添加

-G "Visual Studio 16 2019"

你可能感兴趣的:(opencv,visual,studio,c++,windows,10)