How to compile with g++ and run in ubuntu(linux).

I'm a total newbie and it took me a little while to figure this out, so I made some notes about it as I went along. I hope some other tenderfoot will find this description of this super basic procedure helpful in getting started.

HOW TO COMPILE AND RUN A G++ PROGRAM in UBUNTU
----------------------------------------------

1. Type in source code in gedit
2. Save as filename.cpp
(note that once you save as .cpp gedit will begin to show source code relevent colors whenever the file is opened in gedit)
3. Open terminal (command line) and cd (change directory) over to the directory where you saved the file
4. At the prompt type: "g++ filename.cpp"
5. You may see a load of warnings and recommendations, but if the code has no errors then an executable will still be created.
6. Type "ls" on the command line to see the program titled "a.out" in the current directory
7. If it's there (and wasn't before) that is your compiled file.
8. type "./a.out" to run it!

YAY!!! You did it!

-----------------------------------------------

For lots of information on running the g++ command line compiler see the following url:
http://www.wm.edu/computerscience/computing/gpp.php
ALSO type "man g++" in terminal to access the basic manual of g++ commands
-----------------------------------------------
HOW TO NAME THE FILE SOMETHING BESIDES "a.out"

Instead of typing simply: "g++ filename.cpp" during the compiling step,
type "g++ filename.cpp -o newfilename.exe"

Now to run the program type "./newfilename.exe"

-------------------------------------------

I look forward learning and interacting in this forum!

-ultrajones-
Hey, nice info.

I always add -Wall -pedantic options too, and fix all the warnings and errors listed so that g++ doesn't complain about anything when I compile.

% g++ -Wall -pedantic -o myprog myprog.cpp
%
Thanx Jones, that was quite useful!
Topic archived. No new replies allowed.