Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 654
Jonas Avatar asked Dec 16 '22 23:12

Jonas


1 Answers

  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
like image 139
Sam Harwell Avatar answered Jan 01 '23 12:01

Sam Harwell