Compiling C++

Discussion in 'Command Line' started by Kryyll, Feb 9, 2014.

  1. Kryyll

    Kryyll Member

    Messages:
    75
    Likes Received:
    27
    Trophy Points:
    18
    I decided that I wanted to learn a little C++ in my spare time. I started reading some tutorials and made a really simple hello world program (how else would you start!? :D) and for some reason it won't run.
    When I enter the command
    Code:
    gcc -o foo foo.cc
    I get a message saying that it canny find the iostream directory.
    I know that we don't use iostream.h anymore and have it in the code as
    Code:
    #include <iostream>
    Any ideas?

    Also, what language does one use to program with Ncurses?

  2. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    951
    Likes Received:
    848
    Trophy Points:
    93
    Ncurses can be used with many languages if you have the right bindings and libraries.

    As far as your C++ error, I do not know enough yet to solve the issue.
    Haider92 and ryanvade like this.
  3. Kryyll

    Kryyll Member

    Messages:
    75
    Likes Received:
    27
    Trophy Points:
    18
    I actually figured it out. I'm not sure why but using the gcc command gets that error however if you use
    Code:
    g++ -o foo foo.cc
    it works. Not really sure why.
    ryanvade likes this.
  4. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    889
    Likes Received:
    288
    Trophy Points:
    63
    gcc is for the C programming language while g++ is for the C++ programming language. You cannot use the gcc compiler for C++ and vice-versa.
    ;)
    DevynCJohnson and Kryyll like this.
  5. Kryyll

    Kryyll Member

    Messages:
    75
    Likes Received:
    27
    Trophy Points:
    18
    Well that would explain the C's in gcc and the pluses in g++... Man linux is hard ;D
    ryanvade likes this.
  6. Matesax

    Matesax Member

    Messages:
    54
    Likes Received:
    9
    Trophy Points:
    8
    I recommend D language (GDC) - it's more better than C++... (And it's backward compatible with C++.)
    DevynCJohnson likes this.
  7. KenJackson

    KenJackson Active Member

    Messages:
    129
    Likes Received:
    27
    Trophy Points:
    28
    I'm not interested enough to experiment, but the man page lists an -x switch that lets you choose the language. So you should be able to specify -x c++ to compile C++ with gcc.

    Or you could compile ada, go, java, several flavors of fortran and objective-c and others.
  8. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    889
    Likes Received:
    288
    Trophy Points:
    63
    Code:
      -x language
              Specify explicitly the language for the following input files
              (rather than letting the compiler choose a default based on the
              file name suffix).  This option applies to all following input
              files until the next -x option.  Possible values for language are:
    
                      c  c-header  cpp-output
                      c++  c++-header  c++-cpp-output
                      objective-c  objective-c-header  objective-c-cpp-output
                      objective-c++ objective-c++-header objective-c++-cpp-output
                      assembler  assembler-with-cpp
                      ada
                      f77  f77-cpp-input f95  f95-cpp-input
                      go
                      java
    
    using the -x switch would probably just run the associated compiler.
    DevynCJohnson likes this.

Share This Page