Compiling a C Program in Windows without an IDE

1. Download tcc (Tiny C Compiler), by Fabrice Bellard, from “http://bellard.org/tcc/“.

2. Install tcc on your system by simply uncompressing the downloaded file to the desired directory.

3. In any convenient location, create a new directory and name it “HelloWorld”.

4. Open the newly created HelloWorld directory.

5. In the HelloWorld directory, create a new text file and name it “HelloWorld.c”.

6. Open the newly created HelloWorld.c in a text editor and enter the following text.

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello, world!\n");
    system("PAUSE");
    return 0;
}

7. Save HelloWorld.c and exit the text editor.

8. Still in the HelloWorld directory, create a new text file and name it “ProgramBuild.bat”.

9. Right-click the newly created ProgramBuild.bat file and select “Edit” from the context menu that appears.  The file will be opened in a text editor.

10. Enter the following text, substituting the path of the directory where tcc.exe is located on the first line.  This directory was created in step 2.

set compilerPath="[ the path where tcc.exe is located ]"
for %%* in (.) do (set programName=%%~n*)

%compilerPath%\tcc.exe %programName%.c
pause

11. Save ProgramBuild.bat and exit the text editor.

12. Double-click the icon for ProgramBuild.bat.  A console window will appear and tcc will compile HelloWorld.c.

13. After the compilation is complete, a prompt saying “press any key to continue” will appear.  Press a key to close the console window.

14. In the HelloWorld directory, a new file called “HelloWorld.exe” should now be present.  Double-click the file’s icon to run it.  A console window will appear, and the text “Hello, World!” will be displayed in it.

Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to Compiling a C Program in Windows without an IDE

  1. Thanks for this tutorial-I tried it but unsuccessfully so far:

    C:\Program Files (x86)\Arena\Engines\SecondChess_latest\pocopito-secondchess-v0.
    1-35-gd1633e5\pocopito-secondchess-d1633e5>”[ C:\Users\Richard\Downloads\tcc-0.9
    .25-win32-bin\tcc ]”tcc.exe pocopito-secondchess-d1633e5.c
    The filename, directory name, or volume label syntax is incorrect.

    C:\Program Files (x86)\Arena\Engines\SecondChess_latest\pocopito-secondchess-v0.
    1-35-gd1633e5\pocopito-secondchess-d1633e5>pause
    Press any key to continue . . .

    • Sorry to hear you’re having trouble. You might try removing the brackets (“[” and “]”) around your directory name. When I tried adding them to mine, it failed the same way yours did. Oh, I also noticed that you didn’t put a backslash at the end of your compilerPath variable. It hadn’t occurred to me that that might happen, so I updated the ProgramBuild.bat listing to include a “safety” backslash, just in case. Now it works whether you put a backslash at the end of your variable value or not. Hopefully things’ll be a little easier now.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s