views:

99

answers:

4

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.
+1  A: 

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.

DeadMG
Err.. it's most definitely a C compiler. Windows is compiled with something. ;) Though there are some nonstandard extensions, like every compiler has.
Billy ONeal
Is this really the only way? By creating a C++ project, I create tons of different files. Using the article I linked to, only a `.c` file, an `.obj` file and an `.exe` file is created.
Jonas
@Jonas: Many extras are created with a project, like Intellisense databases, partial rebuild files, etc. All of these files have uses that your article can't match. Whether or not you actually use them is another matter. What you should do is ignore the extra files unless they take up excessive space or your builds stop working. Until then, ignore. @Billy ONeal: Yeah, the C++ compiler.
DeadMG
@DeadMG: thanks that was informative. Intellisense is very useful.
Jonas
+2  A: 

Just go into your project properties, and change the setting under C\C++ -> Language -> Compile As: to "Compile as C code".

Billy ONeal
Is there no way to do this without creating a C++ project which creates tons of files?
Jonas
One of the options when you create a project is "Create an empty project."
jwismar
-1: If the file has a `.c` extension, this is already set. (-1 because it's not useful as an *answer*)
280Z28
@280Z28: That depends on how you add the actual file. If you add it using the Visual Studio GUI, and you add it as a .c file, then yes, I believe that option is set by default. However, if you merely rename an existing file to .c, which was imported with the C++ extension, that option will need to be changed.
Billy ONeal
@Billy ONeal: That is not correct. I just tried it - renaming the file immediately resulted in compilation errors for C++ elements within it. If the project was incorrectly manually configured by explicitly turning on C++ mode for all files instead of just leaving the setting alone, then yes, you would have to go back and change it the other way.
280Z28
A: 

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.

JC Leyba
+2  A: 
280Z28
+1. Also note that anything in the ipch directory and any file with a .ncb extension should also be excluded from source control.
Billy ONeal