Compile C app with Visual Studio 2012

爱⌒轻易说出口 提交于 2019-11-30 03:58:27
Alexander Galkin

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,

  1. Right Click to Project Properties
  2. C/C++
  3. Advanced
  4. Set "Compile As" to "Compile as C Code(/TC)"

To demonstrate it visually, check the screen-shot below;

Steps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!