Thursday, February 18, 2010

Compiling C code using Visual Studio .Net

This applies to older version of Visual Studio .Net (before 2008) as well but I haven't tested.

I recently got some code in C that needed to be setup in a visual studio project. Its not hard but I thought I'd still share the information:

  • Start with a new project. 
  • Select Visual C++ "Win32 Console Application".
  • Check the  "Empy Project" in Application Settings along with leaving the default radio "Console Application" checked
  • Add your files to the newly created project
  • Select "Project Properties -> c/c++ -> Advanced" and set the option "Compile As" to "Compile as C Code" (/TC) 
  • Click OK
All set :) Just Build (Ctrl+Shift+B)

Enjoy!

4 comments:

  1. Thanks for the info. I tried to create a project and build some old C code, and got and error with cerrno. It seems to have a problem with the "using :: errno;" in cerrno If you would happen to have any ideas, would be appreciated. Try to make a build of something old for someone. Thanks.

    ReplyDelete
  2. using is for namespaces which I believe are available in c++ not c (can you see any classes in your code? if so its c++).
    So you might want to uncheck "Compile as C Code"

    ReplyDelete
  3. Plz tell me how to compile a project via command line... I am used to work using geany editor and comile via gcc but in my University, it is quite pathetic to start project for even single line of code in VS...

    ReplyDelete