Compile C app with Visual Studio 2012

落花浮王杯 提交于 2019-12-18 11:32:19

问题


I plan to write application in C using Microsoft Visual Studio 2012. The problem is that I can't find a way to compile it right in the editor. I found this solution http://msdn.microsoft.com/en-us/library/bb384838.aspx but I dont like it. Can you recommend me a way to compile C program right in the Visual Studio 2012?


回答1:


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.




回答2:


Also check "properties -> c/c++ -> advanced -> Compile as" make sure it says "c code"

or on the command line use /TC




回答3:


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).




回答4:


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.




回答5:


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..




回答6:


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



来源:https://stackoverflow.com/questions/8579894/compile-c-app-with-visual-studio-2012

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