Jonas
Jonas

Reputation: 128807

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

Upvotes: 4

Views: 28636

Answers (3)

Sam Harwell
Sam Harwell

Reputation: 99869

  1. File → New → Project...
  2. 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.
  3. In the Solution Explorer for the new project, right click Source Files and select Add → New Item.
  4. 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;
    }
    
  5. 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

Upvotes: 9

JC Leyba
JC Leyba

Reputation: 520

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.

Upvotes: 1

Puppy
Puppy

Reputation: 146910

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.

Upvotes: 2

Related Questions