Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    how to program in C++ in linux

    Hi, i have fedora core 4, and starting to learn C++.
    To program in perl on linux, you would ----> " perl "
    How do you program in C++ on linux?

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    Righto. Let's say that you have your source saved in hello.cpp.

    g++ -Wall -o hello hello.cpp
    Allow me to explain:

    g++ - Invoke the GNU C++ Compiler
    -Wall - Enable all warnings
    -o hello - Name the outputted binary "hello" (if -o is not given, the binary is called a.out)
    hello.cpp - The file to compile

    So in this case, we have called the binary "hello", and so can execute the program via:
    assuming that you are currently in the same directory as the binary.

    Hope that helps!


    Let it be noted that there is a difference between how Perl and C++ run. Perl, you write your source and just run it: it is compiled and executed automatically. In C++, the source and program are different files: you must manually compile the program (using g++) before you can run it.

  3. #3

  4. $spacer_open
  5. #4
    If you want to write programs with multiple source files, or programs with complex compile options, or programs you plan on distributing in source form, it's a good idea to use make.

  6. #5
    thanx for that, now after the compile, how do you run the program?
    i tried " ./hello.cpp "
    ************************************************** *******************
    /home/max/hello.cpp: line 3: using: command not found
    /home/max/hello.cpp: line 5: syntax error near unexpected token `('
    /home/max/hello.cpp: line 5; `int main(void)`
    ************************************************** ************************************************** *******

  7. #6
    Linux Guru AlexK's Avatar
    Join Date
    Feb 2005
    what you did with that last command was to try and run the file which contains the source code and not the executable.

    I suggest you read through Cabhan's post again.

    hint:: note how he runs the program with ./hello i.e. the executable and not the source code.
    Life is complex, it has a real part and an imaginary part.

  8. #7
    Just Joined!
    Join Date
    Sep 2005
    Nowhere and Everywhere
    When you compile a program, do you need to be in root??

  9. #8
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Quote Originally Posted by southpaw
    When you compile a program, do you need to be in root??
    No, you do not.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

Posting Permissions

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