Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C-code from the Command Prompt in Windows?

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?

like image 288
Chris_45 Avatar asked Aug 26 '09 12:08

Chris_45


People also ask

Can we compile C program in command prompt?

Create a C source file and compile it on the command line. In the developer command prompt window, enter cd c:\ to change the current working directory to the root of your C: drive. Next, enter md c:\hello to create a directory, and then enter cd c:\hello to change to that directory.

How do you compile using CMD?

Programs can be created and modified using the Update Processor. Additionally, programs can be compiled when exiting the Update Processor by using either the CTRL+XC command, which compiles and catalogs the program, or the CTRL+XR command, which compiles and runs the program. Any other editor can also be used.


3 Answers

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!
like image 99
RichieHindle Avatar answered Oct 02 '22 09:10

RichieHindle


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

like image 41
Yusuf X Avatar answered Oct 02 '22 09:10

Yusuf X


  • open command prompt
  • type path c:\tc\bin
  • goto your project folder in command prompt
  • type tcc filename.c
  • after compilation type filename
like image 2
RUbesh Avatar answered Oct 01 '22 09:10

RUbesh