How to compile C++ for Windows with clang in Visual Studio 2015

后端 未结 4 2035
死守一世寂寞
死守一世寂寞 2021-01-30 16:48

As far as I understand, Visual Studio 2015 is shipped with clang. First I though this was only for Android and iOS apps, but according to this article it should also be possible

相关标签:
4条回答
  • 2021-01-30 17:13

    As far as I understand it both Clang and GCC are shipped with the Android and iOS crossplatform SDKs/tools for Visual Studio 2015.

    From what I've seen it only allows me to choose those while having one of those crossplatform projects.

    Using the template project for a GLES C++ application you get the following options:

    While for a Windows C++ application you get the dialog below where you can see that Windows target platform is grayed out and read-only, meaning you probably have a set of toolkits for each target platform, but you simply cannot change it, at least for now.

    Have no idea how you turn a normal VS project into crossplatform though, and it's likely that you can only target Android or iOS out of the box using 3rd party compilers.

    It may be possible, though, to install Clang as another toolkit in the same way the XP toolkits are. So perhaps it's just a matter of someone fiddling with it and making it available as it is already installed.

    Caveat: This answer is pre-VS2015 update 1 which didn't have the "Clang with Microsoft CodeGen" option.

    0 讨论(0)
  • 2021-01-30 17:14

    Starting with VS2015 Update 1 you can install the "Clang with Microsoft CodeGen" template via the New Project window, browse to Installed -> Templates -> Visual C++ -> Cross Platform.

    You will then be able to choose the Clang 3.7 with Microsoft CodeGen v140_clang_3_7 Platform Toolset in the properties page of any Windows C++ project.

    Clang has a completely different set of command-line options which it recognizes, so when using the v140_clang_3_7 toolset, the project properties must be using Clang-compatible options, which can be recognized as starting with - instead of /. For example, Debug Information Format property set to "Full Debug Information (DWARF2) (-g2 -gdwarf-2)", and Enable C++ Exceptions property set to "Yes (-fexceptions)".

    There's more information in this blog post.

    0 讨论(0)
  • 2021-01-30 17:18

    While the above solutions work they require that you have installed clang which is off by default in the visual studio 2015 installation. The accepted answer does show how to install it, though the next page will ask you to close visual studio which you are running the new project from.

    If anyone is wondering how to install clang because it does not show up in their list here is another solution:

    1. Control Panel->Programs->Programs and Features.
    2. Right click on “Microsoft Visual Studio Enterprise 2015” (or “Microsoft Visual
    3. Studio 15 Preview” if you have the preview of the next version of Visual Studio installed)
    4. Click “Change”
    5. Click “Modify”
    6. Select “Clang with Microsoft CodeGen” – The March 2016 release.

    https://blogs.msdn.microsoft.com/vcblog/2016/03/31/clang-with-microsoft-codegen-march-2016-released/

    0 讨论(0)
  • 2021-01-30 17:23

    After reading through the linked post and especially the comments again, I came to understand, that this is not a feature shipped with VS2015 RC but a possible future feature that might e.g. be shipped in a SP or (more likely) with the next version of VS.

    As mentioned by sjdowling, the closest thing you can do at the moment (October 2015, clang 3.7) is to download and install llvm for windows. This should give you a LLVM-vs2014 platform toolset option. For me it works for simple test programs, but apparently this version of "clang-vs" seems to not yet support exceptions. However, according to these notes, that problem should be mostly solved for clang 3.8.

    0 讨论(0)
提交回复
热议问题