Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I want to get started in C++ programming. I am running Ubuntu 7.10 and first need a compiler. I tried downloading g++ from synaptics package manager but when I ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    19

    C++ programming

    Hello,

    I want to get started in C++ programming. I am running Ubuntu 7.10 and first need a compiler. I tried downloading g++ from synaptics package manager but when I check for its installation under Add/Remove Applications It is not listed. I don't need a tutorial on how to program in C++ since I have and older copy of a book. What I need is advice on how to download and setup the compiler and run a hello world program I created in gedit. Can someone tell me how to download the compiler and run main.cpp (my hello world program) from the tutorial directory in my home directory? I have searched google for over an hour with no luck. Thanks. BTW, here is the program I will run:

    #include<iostream>

    using namespace std;

    int main(){
    cout << "hello world!\n";
    return 0;
    }

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    If you've searched Google for beginning C++ programming with GCC and haven't found anything, you're obviously not using the right search terms. At any rate, here's what you'll need to get started.

    Open up a terminal. Type this:

    Code:
    sudo apt-get update <enter>
    Password: <enter your password>
    Assuming you have an internet connection, you will see lots of messages about updates and whatnot. Then when you get your prompt back, type this:

    Code:
    sudo apt-get install build-essential
    That will get you a working Gcc/G++ enivronment. Now to compile your code from the command line do this:

    Code:
    g++ nameofyourfile.cpp
    Assuming you don't have any errors, that will generate a program called a.out. You can run it by typing this:

    Code:
    ./a.out
    If you want to name our output program something else, use this:

    Code:
    g++ nameofyourfile.cpp -o nameofyourexecutable
    Replace "nameofyourfile" and "nameofyourexecutable" with whatever applies to you.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    19
    Thanks techieMoe, those were the exact instructions I was looking for. BTW, I was able to find alot of stuff on google, just not what I was looking for. I am still very new to linux but working to overcome that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...