GCC basics

Adam

Super Administrator
Staff member
ADMINISTRATOR
Joined
Apr 4, 2007
Messages
45
Reaction score
4
Points
7
Age
33
Location
California
For those of you using Windows:

After installing MinGW, you'll need to set your PATH environment variable to include the path to the MinGW installation directory/bin. This will allow you to invoke gcc from the command line without having to be within the MinGW/bin directory.

--

You'll find gcc very easy to use. For a simple compilation, you can simply type:

gcc -o output input.c

output is the name of the executable you're compiling. On Windows, you do not need to specify the .exe extension. GCC will automatically provide that for you.

input.c is the name of the file you've written your code in. An example could be:

Code:
int main(int argc, char* argv[]) {

    printf("Hello world!\n");
    return 0;

}
--

Executing the compiled exe will result in "Hello world" being displayed inside of a console window. Execute the application from the command prompt, otherwise it will instantaneously display "Hello world" and then terminate.

--

If you're feeling froggy (and I suggest you do this), explore ISO 9899:1999 (the C99 standard), and adhere to it when writing your code). GCC can help facilitate this if you pass -std=c99 -pedantic -Wall as arguments when you invoke it.
 

fop_archer

Make Money Online
Joined
Aug 9, 2009
Messages
663
Reaction score
32
Points
27
Age
32
Location
MMD
Even though i didn't understand :boring: a single sentence from the above post i thank you for it. :D
 

Adam

Super Administrator
Staff member
ADMINISTRATOR
Joined
Apr 4, 2007
Messages
45
Reaction score
4
Points
7
Age
33
Location
California
Even though i didn't understand :boring: a single sentence from the above post i thank you for it. :D
GCC is a C compiler. Basically, it takes the code I posted above and turns it into a program that you can run.

MinGW contains a port (the code has been modified to allow it to run on another platform; in this case, that is Windows) of the GNU C Compiler (GCC).

My example above shows you how to compile (through GCC) a trivial program (the code example) into a program that you can run.

The last part suggests you adhere to ISO standards. It helps somewhat to avoid sloppy unmaintainable code.
 

fop_archer

Make Money Online
Joined
Aug 9, 2009
Messages
663
Reaction score
32
Points
27
Age
32
Location
MMD
i got that now...:banghead:....the whole thing was about compilingand execution. :rofl:
 

dgoiko

Make Money Online
Very Active Members
Joined
Sep 10, 2010
Messages
87
Reaction score
1
Points
0
Age
29
Thank you.
I dont know if you allow to promote other forums, I guess you dont.
Anyway, as this forum is not competing with you in any way, I think you can make an exception.
Code:
http://elhack€r.net
It's a forum in Spanish about programming. If the learner knows spanish, its a great source of information for beginers or experts.
Even tho the word hack€r is on the tittle, they do not support/encourage any h4ck1ng malicious action. In terms of h4ck1ng, they're a security forum, learn how people hack to avoid beign hack€d. Anyway, the programming languajes manuals are great. If this kind of forum refering is not alowed, please, edit my post, but as its not an IM, neither an english forum I think it will be fine
 

rtpl

Make Money Online
Joined
Dec 5, 2010
Messages
93
Reaction score
0
Points
0
Age
35
gcc is a compiler in which u compile your c++ programs