15

I want to compile C code from the Command Prompt in Windows. I have added the environment variable to the PATH and I can compile .cs files with: csc app.cs

That's OK, but how do I compile app.c?

3 Answers 3

26

You do this:

cl app.c

Here's a complete transcript, including setting up the environment for Visual Studio 2005 (change "8" to "9.0" for Visual Studio 2008).

C:\src\tests>"\Program Files (x86)\Microsoft Visual Studio 8\vc\bin\vcvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

C:\src\tests>type app.c
#include <stdio.h>
int main(void)
{
    printf("Hello world!\n");
    return 0;
}

C:\src\tests>cl app.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation.  All rights reserved.

app.c
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:app.exe
app.obj

C:\src\tests>app
Hello world!
Sign up to request clarification or add additional context in comments.

2 Comments

wow !! great.. but i have one problem here. But, once i close command prompt, its not working. Do you know any permanent solution. I mean, once i set the environment, it will be set permanently. Thnaks
@var___: Method 1: If you look at that batch file, it calls another batch file which just sets a bunch of environment variables. You could set those variables system-wide via the Control Panel (system, advanced, environment variables). Method 2: Rather than using a normal command prompt, launch the Visual Studio Command Prompt, which is available in your Start menu and has the environment all set up for you.
2

MinGW provides a popular command-line GCC compiler for Windows.

1 Comment

MinGW for First Time Users HOWTO for more details of how to move on with MinGW.
2
  • open command prompt
  • type path c:\tc\bin
  • goto your project folder in command prompt
  • type tcc filename.c
  • after compilation type filename

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.