GCC basics

Discussion in 'C/C++' started by Adam, Oct 8, 2009.

  1. Adam

    Adam Super Administrator Staff Member ADMINISTRATOR

    Joined:
    Apr 4, 2007
    Messages:
    45
    Likes Received:
    4
    Trophy Points:
    8
    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.
     
  2. fop_archer

    fop_archer Make Money Online

    Joined:
    Aug 9, 2009
    Messages:
    663
    Likes Received:
    32
    Trophy Points:
    28
    Location:
    MMD
    Even though i didn't understand :boring: a single sentence from the above post i thank you for it. :D
     
  3. Adam

    Adam Super Administrator Staff Member ADMINISTRATOR

    Joined:
    Apr 4, 2007
    Messages:
    45
    Likes Received:
    4
    Trophy Points:
    8
    Location:
    California
    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.
     
  4. fop_archer

    fop_archer Make Money Online

    Joined:
    Aug 9, 2009
    Messages:
    663
    Likes Received:
    32
    Trophy Points:
    28
    Location:
    MMD
    i got that now...:banghead:....the whole thing was about compilingand execution. :rofl:
     
  5. octars

    octars Make Money Online Very Active Members

    Joined:
    Aug 17, 2009
    Messages:
    108
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Forum$$
    I don't Understand either but thanks, someday must be useful
     
  6. dgoiko

    dgoiko Make Money Online Very Active Members

    Joined:
    Sep 10, 2010
    Messages:
    87
    Likes Received:
    1
    Trophy Points:
    0
    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
     
  7. rtpl

    rtpl Make Money Online

    Joined:
    Dec 5, 2010
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    0
    gcc is a compiler in which u compile your c++ programs
     

Share This Page