How do I create a C project in visual Studio 2019? - c

I installed Visual Studio 2019 and I want to create a C project.
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.
I see no option for a C solution.
There is a doc on the net explaining how to create C project in console from command line. 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. Kudos to the video creator and kiner_shah for sharing.
As a precondition, you shall be able to create C++ project in VS, so make sure you have the right extensions installed.
Create a new project (Shift+Ctrl+N), select Visual C++ and Console App. This will create a new console app with a default c++ main file. Remove that file and put in a main.c file. 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.
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.

C++ can already run C code. So just change the extension from *.c or *.i to *.cpp and it should work. It's not a GUARANTEE, but 95% of the tome it works.

Select File > New > Project, then select C++, Windows, Desktop, then select empty project in the new project menu. 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.

Related

Create C project by default in Clion

I have been using Clion in Windows where i get an option to choose what type of project i wish to create (c/c++) but in Mac it doesn't ask me to choose between the type of project. It is set c++ by default. However renaming .cpp to .c again and again, following this How to create a C project with CLion doesn't seem like a cool idea (time consuming). So, is there any option in setting/ preferences in which I can set cLion to create C project by default?
Greetings from germany,
unfortunately there is still no project wizard implemented.
Have a look at this answer:
"You can create C++ project and them rename main.cpp file for now. In the future we are probably planning C project in project creating wizard."
- posted by Anastasia Kazakova on 17 Oct 2015, 16:56.
Source: https://youtrack.jetbrains.com/issue/CPP-4749
I have just found an answer to this question. JetBrains has yet not introduced this feature to their IDE.
They will include this feature in the next update: see this link

C programming in Visual Studio

Can I use Visual Studio to learn C programming? In the new project menu I can choose between Visual Basic, Visual C#, Visual C++, Visual F# and others but I don't see "C" or "Visual C".
Short answer: Yes, you need to rename .cpp files to c, so you can write C:
https://msdn.microsoft.com/en-us/library/bb384838.aspx?f=255&MSPPError=-2147217396
From the link above:
By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of file name extension, use the /Tc compiler option.
That being said, I do not recommend learning C language in Visual Studio, why VS? It does have lots of features you are not going to use while learning C
Yes, you very well can learn C using Visual Studio.
Visual Studio comes with its own C compiler, which is actually the C++ compiler. Just use the .c file extension to save your source code.
You don't have to be using the IDE to compile C. You can write the source in Notepad, and compile it in command line using Developer Command Prompt which comes with Visual Studio.
Open the Developer Command Prompt, enter the directory you are working in, use the cl command to compile your C code.
For example, cl helloworld.c compiles a file named helloworld.c.
Refer this for more information: Walkthrough: Compiling a C Program on the Command Line
Hope this helps
Yes it is, none of the Visual Stdio editions have C mentioned, but it is included with the C++ compiler (you therefore need to look under C++). The main difference between using C and C++ is the naming system (i.e. using .c and not .cpp).
You do have to be careful not to create a C++ project and rename it to C though, that does not work.
Coding C from the command line:
Much like you can use gcc on Linux (or if you have MinGW installed) Visual Studio has a command to be used from command prompt (it must be the Visual Studio Developer Command Prompt though). As mentioned in the other answer you can use cl to compile your c file (make sure it is named .c)
Example:
cl myfile.c
Or to check all the accepted commands:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27030.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>
Coding C from the IDE:
Without doubt one of the best features of Visual Studio is the convenient IDE.
Although it takes more configuring, you get bonuses such as basic debugging before compiling (for example if you forget a ;)
To create a C project do the following:
Start a new project, go under C++ and select Empty Project, enter the Name of your project and the Location you want it to install to, then click Ok. Now wait for the project to be created.
Next under Solutions Explorer right click Source Files, select Add then New Item. You should see something like this:
Rename Source.cpp to include a .c extension (Source.c for example). Select the location you want to keep it in, I would recommend always keeping it within the project folder itself (in this case C:\Users\Simon\Desktop\Learn\My First C Code)
It should open up the .c file, ready to be modified. Visual Studio can now be used as normal, happy coding!
Yes, you can:
You can create a C-language project by using C++ project templates. In the generated project, locate files that have a .cpp file name extension and change it to .c. Then, on the Project Properties page for the project (not for the solution), expand Configuration Properties, C/C++ and select Advanced. Change the Compile As setting to Compile as C Code (/TC).
https://learn.microsoft.com/en-us/cpp/ide/visual-cpp-project-types?view=vs-2017
You can use Visual Studio for C, but if you are serious about learning the newest C available, I recommend using something like Code::Blocks with MinGW-TDM version, which you can get a 32 bit version of. I use version 5.1 which supports the newest C and C++. Another benefit is that it is a better platform for creating software that can be easily ported to other platforms. If you were, for example, to code in C, using the SDL library, you could create software that could be recompiled with little to no changes to the code, on Linux, Apple and many mobile devices. The way Microsoft has been going these days, I think this is definitely the better route to take.
Download visual studio c++ express version 2006,2010 etc.
then goto create new project and create c++ project select cmd project check empty rename cc with c extension file name

Compile C app with Visual Studio 2012

I plan to write application in C using Microsoft Visual Studio 2012.
The problem is that I can't find a way to compile it right in the editor. I found this solution http://msdn.microsoft.com/en-us/library/bb384838.aspx but I dont like it.
Can you recommend me a way to compile C program right in the Visual Studio 2012?
It is a little bit tricky to compile plain C90 and C++x0 (only partially supported) projects in VS2010 (and probably Visual Studio 11, I haven't tried native development in it yet).
What you have to do is to create a new C++ project without precompiled header -- this is the primary requirement if you want to compile a platform-independent code (library, console application).
There are several ways to do it. One way is to create a normal Win32 C++ console application, in the opened wizard you should go to the second page (by clicking "Next") and then uncheck the option "Include precompiled header". Then you can compile C++ (and C) projects directly in VS.
Also check "properties -> c/c++ -> advanced -> Compile as" make sure it says "c code"
or on the command line use /TC
Create an empty C++ project in Visual Studio (File -> New Project -> Visual C++ -> Empty Project), then add a source file with a .c extension to it (right click the project, select Add -> New Item -> C++ File (.cpp), and change the name of the file).
When you build, the compiler will compile it as C code (note that Visual C++ supports only C90, not C99, so newer C language features are not usable).
By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of file name extension, use the /Tc compiler option.
Source: MSDN Visual Studio 2013, http://msdn.microsoft.com/en-us/library/bb384838.aspx walkthrough
Go to Menu command to open "Project -> Properties" dialogue. Then in "Configuration Properties" select "C/C++ -> Advanced" pane. Change "Compile As" drop-down box from "Default" to "Compile as C Code (/TC). Click on "Apply" button and then "OK" to close the dialogue.
select new project,win 32console application ,uncheck precompiled header,select empty project.. Then add a new item,select..cpp file then rename the file with .c.extension and you're done to compile c codes..
It's also same for newer VS versions, what you have to do is as mentioned by #Alexander Galkin,
Right Click to Project Properties
C/C++
Advanced
Set "Compile As" to "Compile as C Code(/TC)"
To demonstrate it visually, check the screen-shot below;
Steps

How can I use Visual Studio 2010 for C development?

I would like to do some C development in Windows environment using Visual Studio 2010. There are a few similar questions on this topic, but they are all based on that you are creating a Win32 console application, and a C++ project.
How can I do C development using only .c and .h files as I do in Unix? without creating a C++ projects containing tons of files.
It is possible to do C compiling with the cl compiler from outside of Visual Studio 2010, see Walkthrough: Compiling a C Program. But how can I do this compilation and execution/debugging from inside Visual Studio 2010?
UPDATE
I have tried to create a C++ project (Win32 Console Application) and only add .c files to it. It works but it creates tons of files.
I have tried with a C++ project (Empty project), but it also created a lot of project files.
Basically what I want is to only create .c and .h files, use the cl compiler, and use Visual Studio 2010 as a text editor. And use a command to compile from the text edior, but it seems like I have to compile in a command prompt.
File → New → Project...
Under C++, choose Empty Project. If you want to minimize the number of folders created, uncheck the box to Create Directory for Solution. Give the project a name and location and click OK.
In the Solution Explorer for the new project, right click Source Files and select Add → New Item.
Choose C++ File (.cpp), and give it a name like SomeName.c. Make sure to specify the .c extension. Add the following code:
int main(int argc, char** argv)
{
return 0;
}
If necessary, disable Microsoft extensions to the C language by right clicking the project and selecting Properties. Select All Configurations at the top of the dialog. Then go to C/C++ → Language → Disable Language Extensions: Yes.
Visual Studio will create the following files for your project. Just get used to having them there. Do not check items with a * into source control.
ProjectName.sln
ProjectName.sdf*
ProjectName.suo*
ProjectName.vcxproj
ProjectName.vcxproj.user*
ProjectName.vcxproj.filters
somename.c
If you compile a file that has the .c extension, VS will use it's C compiler. However, you should be aware that said C compiler isn't C99 conformant (or even C89 for some cases, if I remember correctly). Visual Studio is not really a C compiler, it's C++ mostly. You will have to use a C++ project and simply include .c files.
VS actually has a very capable C compiler, somethng that people overlook all too often. The above answers will point you in the right direction, but it's by no means low quality like I've heard people say in the past.

Maintain C projects in Visual Studio 2010?

Do you know of any extension (desired free) for VS (or VCPP) 10 that adds C projects productivity (i.e. templates, headers control, syntax highlighting etc.)?
Thanks
Visual Studio already ships with support for C. That includes project files, a compiler, header files, syntax highlighting and debugging support. What are you missing (apart from C99)?
Create a standard C++ project such as a Win32 Console Application (it doesn't matter which one).
Add a new item (Project menu, Add New Item...) and select "C++ File (.cpp)"
Here is the important step. Give the file a ".c" extension rather than a ".cpp" extension. By calling the file ".c", Visual Studio will compile it as C instead of C++.
Create a Win32 C++ project and from the Solution Explorer right-click your projcet and select Properties -> Configuration Properties -> C/C++ -> Advanced -> Compile As -> Compile As C., then rename the *.cpp extensions to *.c and build your project.
You may want to delete some unimportant files like stadfx.cpp and targetver.h (remove its linkage from stdafx.h).

Resources