Thursday, July 9, 2009

How to Compile Using TCC (Tiny C Compiler)?

I am a complete beginner to programming languages and I'm not sure how to compile. I just downloaded TCC (Tiny C Compiler), but have no idea how to use it. If I were to compile this code:





//include this file for cout


#include %26lt;iostream.h%26gt;





int main() {





//print out the text string, "Hello, World!"


cout %26lt;%26lt; "Hello, World!" %26lt;%26lt; endl;





return 0;





Any help would be greatly appreciated. THANKS (=!

How to Compile Using TCC (Tiny C Compiler)?
That's C++ code. TCC cannot compile that because it is only a C compiler. C is very similar, except the standard library isn't as extensive (and there's several other differences in the language itself).





If you want to compile a basic C program, try the following:





#include %26lt;stdio.h%26gt;





int main()


{


printf("Hello, World!\n");


return 0;


}





Save that in a file like test.c and then open a DOS box (Command Prompt on WinXP). Type:





set PATH=THE_DIRECTORY_YOU_PUT_TCC;%PATH%


cd the_full_path_to_the_folder_with_test.c


tcc test.c





Replace THE_DIRECTORY.. with the C:\.... to the folder where you put TCC (if it has spaces you'll need double quotes around it), and then replace the_full_path... with the folder that has test.c (again if it has spaces...). Then tcc will have created a test.exe that you can run by typing "test" alone on a line (probably needs to not have the quotes).





Sorry if any of this is obvious, you didn't say how much experience you have with command lines.

sweet pea

No comments:

Post a Comment