How can I use Visual Studio 2010 development for C?

I would like to do some C development in Windows using Visual Studio 2010. There are several similar questions on this topic, but all of them are based on the fact that you are creating a Win32 console application and a C ++ project.

How do I create C development using only .c and .h files, as I do on Unix? without creating C ++ projects containing many files.

You can do this C compilation with the cl compiler from outside of Visual Studio 2010, see the Walkthrough. Compilation of the program C. But how can I do this compilation and execution / debugging from Visual Studio 2010?

UPDATE

  • I tried to create a C ++ project (Win32 console application) and add .c files to it. It works, but it creates a lot of files.
  • I tried the C ++ project (empty project), but it also created a lot of project files.
  • Basically what I want is to just create .c and .h files, use the compiler cl , and use Visual Studio 2010 as a text editor. And use the command to compile from edior text, but it seems to me that I should do the compilation on the command line.
+4
source share
3 answers

If you compile a file with the extension .c, VS will use its C compiler. However, you should know that the specified C compiler is not compatible with C99 (or even C89 for some cases, if I remember correctly). Visual Studio is not really a C compiler, mostly C ++. You will need to use the C ++ project and just include the .c files.

+2
source
  • File β†’ New β†’ Project ...
  • In the C ++ section, select "Empty project." If you want to minimize the number of folders created, uncheck the "Create directory for solution" box. 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.
  • Select the C ++ file (.cpp) and give it a name like SomeName.c . Be sure to include the .c extension. Add the following code:

     int main(int argc, char** argv) { return 0; } 
  • If necessary, disable Microsoft C extensions by right-clicking the project and choosing Properties. Select "All configurations" at the top of the dialog box. 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 * in the source control.

  • ProjectName.sln
  • ProjectName.sdf *
  • ProjectName.suo *
  • ProjectName.vcxproj
  • ProjectName.vcxproj.user *
  • ProjectName.vcxproj.filters
  • somename.c
+9
source

VS actually has a very capable C compiler, because people skip it too often. The above answers will point you in the right direction, but this is by no means a low quality, as I heard in the past.

+1
source

All Articles