Enabling C++14 in clang in Visual Studio

后端 未结 2 1586
小鲜肉
小鲜肉 2020-12-30 08:02

I\'ve installed clang 3.7 and I\'m using it with visual studio. When I try to compile:

auto f()
{
return 2;
}

I\'m getting error saying tha

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 08:53

    clang-cl doesn't use the same option syntax as traditional clang - it's supposed to mimic Visual Studio's cl command line, not clang's command line.

    For instance, from clang-cl's documentation:

    CL.EXE COMPATIBILITY OPTIONS:
      /?                     Display available options
      /arch:          Set architecture for code generation
      /C                     Don't discard comments when preprocessing
      /c                     Compile only
      /D      Define macro
      ...
    

    Notice that those options are similar to Microsoft's cl option syntax, not clang's option syntax.

    However, they have a little pass-through option to support cases like yours:

    OPTIONS:
      ...
      -Xclang          Pass  to the clang compiler
      -mllvm         Additional arguments to forward to LLVM's option processing
    

    And so it would seem that invoking clang-cl -Xclang -std=c++14 would be your best bet.

提交回复
热议问题