Find the answer to your Linux question:
Results 1 to 5 of 5
First what is the difference between doing a gcc and a g++? You can answer that question, but that is really a-side to what I really need to know. I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57

    trying to get gcc to work


    First what is the difference between doing a gcc and a g++?

    You can answer that question, but that is really a-side to what I really need to know. I am a real newbie at all this linux stuff, and I wanted to setup a IDE for C++ programming. But apparently all the C libraries aren't configured right, or they are not in my path. The error message when I did a simple "hello world" program, said
    test1.cc:4:18: stdlib: No such file or directory

    I am guessing that means the STL isn't in the path. But I have no idea where all these things are. I just know gcc was intalled when I installed RH (because I chose nearly all the packages to install).

    And another thing, do people do"
    #include <stdlib.h>
    or without the .h? I don't get it?

  2. #2
    Just Joined!
    Join Date
    Mar 2003
    Posts
    10
    I'm not sure I completly understand your post but I'll try to help.

    1. I believe g++ just lets gcc know that you intend to compile C++ code rather than C. gcc is pretty smart and a top notch compiler that can compile a bunch of different langs. C++ just being one more of many. Sam's teach yourself C for linux - is a great book and can help you with included lib funcs...However I'm not sure if they made a C++ book...and if you already know C++ on another OS then the beginning of the book will be boring. There is another book by Osbourne Press call "GCC the complete reference" - this may be the droid your looking for .

    2. I never got the error you posted so I am really not sure. However I would gamble that it does not recognize the library function you called for <stdlib> I really don't work on compiled code much (read: never) (i'm into perl ) but I don't recall that lib func.

    3. Why (just out of curiosity) do you want an IDE. I find, and this is just me, that linux as a whole is an IDE unto itself. From the command line you can open a text editor (let me say ViM ) and then write your code to disk and then run it from the same shell. In fact you can make up your own commands with some shell scripts that will further inhance your ability to feel the complete integration of programming with in linux and simplfy commands/options/arguments.
    <my 2 cents> I also think that IDE's hamper ones ability to create in a portable environment, meaning, a text ed is a text ed and a cli is a cli...change some code and you can program on anything for anything</my 2 cents>

    good luck! post with follow ups if you like.

    p.s. use the .h

  3. #3
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Let's remember that C++ has new header files. Most of these leave out the .h and can't be rendered this way. For example, the new iostream.h file is just iostream. There is a new feature in C++ called namespaces. I believe all the new header files are under the 'std' namespace so you'll need to do something like this.
    Code:
    // Note the NEW header file names
    // They don't have the file extension '.h'
    #include <iostream>
    #include <cstdlb>
    using namespace std;
    
    int main&#40;&#41;
    &#123;
       ...
       return 0;
    &#125;
    I'm currently using g++ 2.95 and it's not complaining if I don't use the namespace. However other compilers may or may not complain. I think it's more appropriate to use the namespace. We'll see how that works out in the future versions of g++ compilers.
    The best things in life are free.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57
    Ok, I actually read the "warning message" and it said something to the sense of iostream shouldn't have the .h, and stdlib should...didn't make much sense to me. But I did the following
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    
    int main&#40;&#41;
    &#123;
      cout << "Hello World!\n";
      return 0;
    &#125;
    I also noticed that if you don't but the "using namespace std;" part, you need to put .h on both #includes, and it will still give you a warning message (I guess because the .h on the iostream include is deprecated). That was the impression I got from the warning message, I did it, and it worked, if somebody else can come up with a better explanation, let me know.

  6. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The new headers without .h and namespaces are rather new, so gcc currently supports both options, to maintain backwards compatibility. It issues a warning to suggest you to use the new method, though.

Posting Permissions

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