Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
I am a very newbie at RH 8.0, but I saw that RH had a C++ IDE called Kdevelop. I am trying to use that program, but I am really ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57

    How do I setup Gcc and Kdevelop


    I am a very newbie at RH 8.0, but I saw that RH had a C++ IDE called Kdevelop. I am trying to use that program, but I am really confused by a number of things. First I don't know if my gcc is working correctly. I know I installed it because when I type gcc it doesn't say command not recognized, and it tries to compile things but it runs into issues, and a bunch of error messages flash through the screen.

    How do I know if my gcc is installed correctly. Can I re-install GCC sort of speak, and uninstall the old GCC so that at least I know that part of the issue is not a problem.

    Now as for KDeveloper, I wrote a simple Hello world program, shown below
    Code:
    #include <iostream>
    #include <stdlib>
    
    int main &#40;int argvc, char* argv&#91;&#93;&#41;
    &#123;
        cout << "Hello World" << endl;
        return 0;
    &#125;
    But the compile and run options on the menu aren't highlighted and I can't do either. What is up with that? Obviously it is something really stupid, and I just am not familiar enough with this enviornment or this program to figure it out. If somebody can give me a headsup I greatly appreciate it.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I can't help you with kdevelop, since I use emacs exclusively, but I can help you check if gcc is properly installed.
    First, try and compile the following program, with just the gcc command (remember to name the file .c, not .cpp):
    Code:
    #include <stdio.h>
    
    int main&#40;void&#41;
    &#123;
        printf&#40;"Hello world!\n"&#41;;
    &#125;
    If that works, try compiling your own program manually, with the g++ command (name that file .cpp, not .c).

    If the first works but not the second, you just don't have the C++ front-end for GCC installed. Install the gcc-c++ package if that is the case.

  3. #3
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57
    Well compiling the C program worked, and when I compiled the C++ program this happened.

    test1.cc:2:18: stdlib: No such file or directory
    test1.cc: In function `int main(int, char**)':
    test1.cc:6: `cout' undeclared (first use this function)
    test1.cc:6: (Each undeclared identifier is reported only once for each function
    it appears in.)
    test1.cc:6: `endl' undeclared (first use this function)

    my code is very simply it looks like this
    Code:
    #include <iostream>
    #include <stdlib>
    
    int main &#40;int argvc, char* argv&#91;&#93;&#41;
    &#123;
        cout << "Hello World" << endl;
      return 0;
    &#125;
    perhaps you are write i don't have the GCC compiler done correctly, but at least it looks like it has some idea what GCC is....also what is the difference between gcc and g++, I always thought the command for compiling C++ programs was gcc...hmm?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    OK, I've had enough of this! Could someone tell me what's up with leaving out .h in the include directives of recent C++?!
    Anyway, try stdlib.h, 'cause I'm pretty sure that at least that one is a standard C library. Also, if I've understood the latest development of the C++ standard, you'll also need a "using namespace std;" after your includes to be able to access cout.

  6. #5
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57
    ok, I added the .h to my include and it worked, but it gave me a warning. Something about how I should use the <X> header instead of the <X.h> header. But it didn't work until I added the .h, I don't get it. Here is the exact error message:

    usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.


    hmm? I don't get it. But I didn't add that namespace thing to the end, and it still worked.

  7. #6
    Just Joined!
    Join Date
    Apr 2003
    Posts
    27
    this is why #include <stdlib> does not work in C++. The latest restandardization of C++ has a part that pretty much says that all the include files are antiquated. That's why <iostream.h> is <iostream>. With that came the changing of C headers. In this case, #include <stdlib.h> becomes <cstdlib>. Don't ask why, I don't know =].

    As for 'cout undeclared', that's also because of the most recent restandardization. If your studies of C++, you'll eventually read about namespaces. Namespaces are more or less your own way of scoping variables. All of the built in classes (cout, cin, endl, vector, string, etc.) are in the namespace std. So to use them you have to use :: operator since all those classes are no longer in a global scope. (Ah OOP.... i hate it sometimes)

    ex.

    main() {

    std::cout << "Hello World." << std::endl;
    }

    there are two ways around this:

    // #includes

    using namespace std;

    main() {

    cout << "Hello World." << endl;
    }

    OR

    // #includes

    using std::cout;
    using std::endl;
    //rest of 'using's

    main() {

    cout << "Hello World." << endl;
    }

    Hope all this helps =]

  8. #7
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57
    Thanks for the help, that does help.

    But what I'm confused about is this. Who's got it right? It seems like everybody has their own version of the C++ compiler and libraries, and I don't know what is the most recent build, with what modifications and what requirements. Unlike Java, there is like no real standard authority, does GNU actually have final say on this stuff?

    With Java it seems everything is so clear, who is in charge, who releases the builds. And everybody knows if standard is changed. With C++, I don't even know if the books I am reading are up to date, or if the compiler I'm running is up to date. Just annoying I guess.

  9. #8
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    C++ is indeed standardized, by the ISO. ISO does charge money for its standards, though, so I don't if it's possible to get it for free.

  10. #9
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    0x90,

    Do you know a lot about namespaces? For some strange reason, I can compile code by using the new header files without using namespaces at all. I'm running gcc2.95.
    The best things in life are free.

  11. #10
    Just Joined!
    Join Date
    Mar 2003
    Posts
    57
    actually, I can second that. In fact Dolda was helping me out with some code. I never added the namespace line that you said to (and also I've read to do), and it still compiled and ran. I just did a #include <stdlib.h>

    It gave me some warning messages but it compiled and it ran. I'm not sure which gcc I'm running but I think it is 3.2.2, whatever came with RH 9.0

Page 1 of 2 1 2 LastLast

Posting Permissions

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