【问题标题】:C compiler identification is unknown despite setting CC and CXX variables尽管设置了 CC 和 CXX 变量,但 C 编译器标识未知
【发布时间】:2014-09-19 20:24:10
【问题描述】:

我正在使用命令:

    cmake CC="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe" 
CXX="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe"  -G "Visual Studio 12
 Win64" -DBOOST_ROOT="c:\local\boost_1_56_0" -DBOOST_LIBRARYDIR="c:\local\boost_1_56_0\lib64-
msvc-12.0"  ..

上面写着:

The C compiler identification is unknown

The CXX compiler identification is unknown

当我在那里设置这些变量时怎么可能?

编辑:错误日志文件:

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

The output was:
1
Microsoft (R) Build Engine version 12.0.30723.0
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 21-09-2014 20:17:49.
Project "D:\foo\build\CMakeFiles\3.0.2\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 12.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 /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TC /errorReport:queue CMakeCCompilerId.c
  CMakeCCompilerId.c
Link:
  C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\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:X64 Debug\CMakeCCompilerId.obj
LINK : fatal error LNK1181: cannot open input file 'gdi32.lib' [D:\foo\build\CMakeFiles\3.0.2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\foo\build\CMakeFiles\3.0.2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.

Build FAILED.

"D:\foo\build\CMakeFiles\3.0.2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Link target) -> 
  LINK : fatal error LNK1181: cannot open input file 'gdi32.lib' [D:\foo\build\CMakeFiles\3.0.2\CompilerIdC\CompilerIdC.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.47


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

The output was:
1
Microsoft (R) Build Engine version 12.0.30723.0
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 21-09-2014 20:17:50.
Project "D:\foo\build\CMakeFiles\3.0.2\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 12.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 /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /errorReport:queue CMakeCXXCompilerId.cpp
  CMakeCXXCompilerId.cpp
Link:
  C:\Program Files (x86)\Microsoft Visual Studio 12.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 LNK1181: cannot open input file 'gdi32.lib' [D:\foo\build\CMakeFiles\3.0.2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\foo\build\CMakeFiles\3.0.2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.

Build FAILED.

"D:\foo\build\CMakeFiles\3.0.2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Link target) -> 
  LINK : fatal error LNK1181: cannot open input file 'gdi32.lib' [D:\foo\build\CMakeFiles\3.0.2\CompilerIdCXX\CompilerIdCXX.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.50

【问题讨论】:

    标签: cmake


    【解决方案1】:

    编译器可以通过使用CCCXX 变量来选择,但它比使用-G(生成器)参数要复杂得多。一方面,路径中的斜杠必须是 Unix 样式(/),并且在第一次运行 CMake 配置后它们不会生效,除非清除缓存。

    有关可用生成器选项的列表,请包括 --help 选项

    Boost 库的路径也必须使用 Unix 风格的斜杠 (/)。许多命令将转换 Windows 路径,但在命令行中传递定义时,您会希望始终使用 Unix 样式的路径。

    您的命令将更改为以下内容:

    cmake -G "Visual Studio 12 2013 Win64" -DBOOST_ROOT="C:/local/boost_1_56_0" -DBOOST_LIBRARYDIR="C:/local/boost_1_56_0/lib64-msvc-12.0" ..

    您还需要确保为 Visual Studio 和 x64 正确设置了 PATH 环境变量。这可以通过使用以下命令打开 VS2013 x64 本机工具命令提示符轻松完成:

    cmd /k "%VS120CoMNTOOLS%\..\..\VC\vcvarsall.bat" amd64
    

    此外,您应该确保在尝试之前清除了 cmake 缓存。最简单的方法是删除您的 cmake 构建文件夹,但您也可以使用 CMake-gui 清除缓存。

    【讨论】:

    • 但为什么在 Windows 上使用 Unix 风格的 /
    • @learner 这只是 CMake 选择使用的格式。我已经更新了我的答案以添加更多细节。
    • @learner 我弄错了您使用的生成器,并修改了我的答案。请注意末尾添加的关于设置 PATH 变量的内容。
    • 那么我的生成器参数是否正确?谢谢!
    • 所以我只是做错了正斜杠。我将命令完全更改为您的命令,但仍然出现相同的错误。我也清除了build/ 目录。正如你所说,我运行了vcvarsall.bat 脚本,但由于我的不是amd 处理器,我也尝试了x64 而不是amd64(即,我分别尝试了两者)。这些都不起作用。你认为可能是什么问题?我犯了同样的错误?我会用日志文件编辑问题,如果可以请看一下。
    猜你喜欢
    • 2022-07-12
    • 2014-01-05
    • 2016-03-04
    • 2023-03-16
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多