【问题标题】:Setting cmake's msvc compilers flags on command line using git bash使用 git bash 在命令行上设置 cmake 的 msvc 编译器标志
【发布时间】:2020-10-16 11:14:12
【问题描述】:

有人可以帮助解决以下问题。我正在使用 Cmake + git bash 并在带有 msvc 编译器的 Windows 机器上使用。如果我以以下方式配置项目cmake .. 一切正常,我可以看到以下输出:

-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.24.28319.0
-- The CXX compiler identification is MSVC 19.24.28319.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works

但是,当我尝试设置编译器标志 cmake -DCMAKE_CXX_FLAGS="/MD" .. 时,出现以下错误:

-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.24.28319.0
-- The CXX compiler identification is MSVC 19.24.28319.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

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

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/dev/projects/camshare/microservices/templates/microservice_cpp/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_ce8fa.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

      Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28319 for x64
      Copyright (C) Microsoft Corporation.  All rights reserved.
      Program
      cl /c /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_ce8fa.dir\Debug\\" /Fd"cmTC_ce8fa.dir\Debug\vc142.pdb" /Gd /TP /errorReport:queue  C:/Program Files/Git/MD C:\dev\projects\camshare\microservices\templates\microservice_cpp\build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx
    c1xx : fatal error C1083: Cannot open source file: 'C:/Program': No such file or directory [C:\dev\projects\camshare\microservices\templates\microservice_cpp\build\CMakeFiles\CMakeTmp\cmTC_ce8fa.vcxproj]
      MD
    c1xx : fatal error C1083: Cannot open source file: 'Files/Git/MD': No such file or directory [C:\dev\projects\camshare\microservices\templates\microservice_cpp\build\CMakeFiles\CMakeTmp\cmTC_ce8fa.vcxproj]
      testCXXCompiler.cxx
      Generating Code...

  CMake will not be able to correctly generate this project.

如果我尝试对 windows cmd 做同样的事情,一切正常。您能解释一下问题出在哪里以及如何解决吗?看起来编译器标志被错误地附加(命令行上的奇怪文件/Git/MD)。我也试过 `CXXFLAGS="/MD" cmake .." 得到了同样的结果。

【问题讨论】:

    标签: visual-c++ cmake git-bash


    【解决方案1】:

    问题在于 git bash 正斜杠的修饰,很容易找到解决方案。结束问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      相关资源
      最近更新 更多