简体   繁体   English

如何在 Visual Studio 2019 中创建 C 项目?

[英]How do I create a C project in visual Studio 2019?

I installed Visual Studio 2019 and I want to create a C project.我安装了 Visual Studio 2019,我想创建一个 C 项目。 Not C++ and not C# There is no option for a C solution But the doc says VS is both a C and a C++ compiler.不是 C++ 也不是 C# 没有 C 解决方案的选项 但是文档说 VS 既是 C 又是 C++ 编译器。 I see no option for a C solution.我看不到 C 解决方案的选择。 There is a doc on the net explaining how to create C project in console from command line.网上有一个文档解释了如何从命令行在控制台中创建 C 项目。 But I want to create a "normal" project.但我想创建一个“正常”的项目。

What should I do ?我该怎么办 ?

I'll summarize what was explained in the video someone linked under your question, as I was able to reproduce the steps and create a working C project in Visual Studio.我将总结有人在您的问题下链接的视频中解释的内容,因为我能够重现这些步骤并在 Visual Studio 中创建一个有效的 C 项目。 Kudos to the video creator and kiner_shah for sharing.感谢视频创作者和kiner_shah的分享。

As a precondition, you shall be able to create C++ project in VS, so make sure you have the right extensions installed.作为先决条件,您应该能够在 VS 中创建 C++ 项目,因此请确保安装了正确的扩展。

Create a new project ( Shift + Ctrl + N ), select Visual C++ and Console App.创建一个新项目( Shift + Ctrl + N ),选择 Visual C++ 和 Console App。 This will create a new console app with a default c++ main file.这将使用默认的 C++ 主文件创建一个新的控制台应用程序。 Remove that file and put in a main.c file.删除该文件并放入main.c文件中。 This can be compiled, and works just fine.这可以编译,并且工作得很好。

You should be able to set up the environment by simply adding a ".c" extension to your code.您应该能够通过简单地向代码添加“.c”扩展名来设置环境。 Additionally, you can manually change your environment by opening your file in VS, clicking on the language displayed at the bottom (which should display "Select Language Mode" and choose C.此外,您可以通过在 VS 中打开文件,单击底部显示的语言(应显示“选择语言模式”并选择 C ​​来手动更改环境。

C++ can already run C code. C++ 已经可以运行 C 代码。 So just change the extension from *.c or *.i to *.cpp and it should work.所以只需将扩展名从 *.c 或 *.i 更改为 *.cpp 就可以了。 It's not a GUARANTEE, but 95% of the tome it works.这不是保证,但 95% 的大部头书都有效。

Select File > New > Project, then select C++, Windows, Desktop, then select empty project in the new project menu.选择 File > New > Project,然后选择 C++、Windows、Desktop,然后在新建项目菜单中选择空项目。 Then click on the folder called "Source" and press Ctrl+Shift+A, then in the new item selection, find the box at the bottom of the dialog, then name it .c.然后单击名为“Source”的文件夹并按Ctrl+Shift+A,然后在新项目选择中,找到对话框底部的框,然后将其命名为.c。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio(2019) c 项目中设置 nuklar? - how to setup nuklear in a visual studio(2019) c project? 如何将带有 .c 和 .h 文件的现有项目转换为 Visual Studio 2019 中的动态链接库? - How can I convert an existing project with .c and .h files into a dynamic link library in visual studio 2019? 如何在 Visual Studio 中单元测试和模拟 C 项目 - How do I Unit Test and mock a C project in Visual Studio 如何在 Visual Studio 2019 中仅编译一个 C 文件? - How do I Compile Just One C File in Visual Studio 2019? 如何创建一个使用CLR混合C和C ++的Visual Studio项目? - How can I create a single Visual Studio project that mixes C and C++ using CLR? 从 Visual Studio 2019 中的 C 项目访问 Golang 代码 - Access Golang code from a C project in Visual Studio 2019 如何在 c/c++ 中为参数添加选项? (视觉工作室平台2019) - How can I add options to argument in c/c++ ? ( visual studio Platform 2019 ) 如何在不需要 LIBCD.lib 的情况下在 Visual Studio 6 中编译 C 项目? - How do I compile a C project in Visual Studio 6 without it needing LIBCD.lib? 如何使用Visual Studio在C中创建DLL? - How can I create a DLL in C using Visual Studio? Visual Studio Community 2019 的新手问题:简单 C 项目中的错误代码 LNK2019 和 LNK1120 - Newbie Problems with Visual Studio Community 2019: Error Codes LNK2019 & LNK1120 in a Simple C Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM