Welcome to Kuwait Linux User Group - OpenSource free stuff

Search   in  

 Create an AccountHome | Gallery | Submit News | Your Account | Content | Topics | Top 10  

Modules
· Home
· Advertising
· Downloads
· FAQ
· Forums
· PHP-Nuke Tools
· Stories Archive
· Submit News
· Surveys
· Top 10
· Topics
· Tutorials
· Web Links
· Your Account

Search
Google
Web q8linux.net

  

Using The g++ Compiler Under Linux



MT262: Putting Computer Systems to Work (C++)

 

Using the g++ compiler under Linux

Links:

Summary:

  • To compile source code (g++ proj2.cc)

    • No errors:

      • Source code will be without error and the executable will be written, returning you back to the command prompt.

      • An executable file will be created in the current directory called a.out

      • To run the program, type ./a.out

    • Errors:

      • The code will have a few errors in it and a display of the errors will be shown (no executable file will be written and you will be returned to your command prompt).

  • g++ Flag Options:

    • -g

      • g++ -g source_file.cc

      • allow the executable file to be "debugged" using the GDB debugger.

    • -Wall

      • g++ -Wall source_file.cc

      • show ALL the warning messages

      • Output:

        • Only warnings: executable will still be created

        • Any Errors: messages will an executable not be created

    • -o

      • g++ proj2.cc -o proj2.exe

      • allow to rename the executable file from something other than a.out

  • Many Flag Options:

    • g++ -g -Wall proj2.cc -o proj2

      • This command will compile the source code file proj2.cc such that the executable will be able to be used with the GDB debugger (-g), will show all warning messages when compiled (-Wall), and will create the executable into a file called proj2 (-o proj2).

    • g++ source_file_1 source_file_2 source_file_3...

      • to compile a program that is contained in multiple files and create a single executable

    • g++ functions.cc proj2.cc

      • 3 files: proj2.cc contains the main() function and is the backbone of your program, functions.h contains the prototypes for functions that your program uses, and functions.cc contains the implementations for those functions. To compile these 3 files into one executable.

      • The above command will then compile the two source files and create one executable a.out.

      • YOU DO NOT PUT ANY .h FILES IN THE g++ COMMAND! DOING SO WILL GIVE ERRORS!

    • g++ -g -Wall functions.cc proj2.cc -o proj2

      • This command will compile the two source files functions.cc and proj2.cc so that the executable can be used with the GDB debugger (-g), all compilation warnings will be displayed (-Wall), and the executable file will be called proj2 (-o proj2).

  • man g++   (for more info).

  • notes:

    • g++ = cc = gcc = gcc++ = c++

    • MĚŞĦǼŁ says: ba3den a3lmek shlon etswey optimze for specific cpu 7ag ur application with gcc



Copyright © by Kuwait Linux User Group - OpenSource free stuff All Rights Reserved.

Published on: 2004-08-25 (905 reads)

[ Go Back ]

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest ©2004-2008 by Q8linux.كويت لينكس
PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.30 Seconds