g++ problem

This is a discussion on g++ problem within the Linux Programming forums, part of the Platform Specific Boards category; I am having problems with g++. I have a simple script: Code: #include <iostream.h> #include <stdlib.h> using namespace std; int ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Kansas City
    Posts
    76

    g++ problem

    I am having problems with g++.
    I have a simple script:
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    using namespace std;
    int main()
    
    {
    
    	int x = 5;
    	cout << "test" << endl;
            cout <<  x << endl;
    
    
    
    }
    and I compile it ( g++ Desktop/test.cpp -o run )

    I get a error:
    Code:
    In file included from /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
                     from Desktop/test.cpp:1:
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
    and then this error when I run the script ( g++ run )
    Code:
    In file included from /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
                     from Desktop/test.cpp:1:
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
    [root@localhost ~]# g++ go
    go: In function `_start':
    (.text+0x0): multiple definition of `_start'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.text+0x0): first defined here
    go:(.rodata+0x0): multiple definition of `_fp_hw'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.rodata+0x0): first defined here
    go: In function `_fini':
    (.fini+0x0): multiple definition of `_fini'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o:(.fini+0x0): first defined here
    go:(.rodata+0x4): multiple definition of `_IO_stdin_used'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.rodata.cst4+0x0): first defined here
    go: In function `__data_start':
    (.data+0x0): multiple definition of `__data_start'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.data+0x0): first defined here
    go:(.rodata+0x8): multiple definition of `__dso_handle'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o:(.rodata+0x0): first defined here
    go: In function `_init':
    (.init+0x0): multiple definition of `_init'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o:(.init+0x0): first defined here
    /usr/lib/gcc/i386-redhat-linux/4.1.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
    go:(.dtors+0x4): first defined here
    /usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
    collect2: ld returned 1 exit status
    I did change the iostream.h into iostream and stdlib.h into stdlib, but same thing.

    So what is causing all these errors, and how can I fix it ?

    I am running Fedora Core 7 on VMware

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    You don't type g++ to run it as well.

    It's
    g++ -o prog prog.cpp
    to compile it,

    then
    ./prog
    to run it
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    Kansas City
    Posts
    76
    That's it.

    Thanks !

    Maybee any other usefull tips for g++ for someone coming from programing on windows ?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Advice for people moving from Windows -> *nix? If you're not used to it already, get used to using a terminal window.

    Actually, I would recommend that for Windows users, too.....

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    stdlib.h into stdlib
    <cstdlib>
    The headers inherited from C have a c prefix in their extension-less names.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    <cstdlib>
    The headers inherited from C have a c prefix in their extension-less names.
    Likewise for
    Code:
    #include <iostream.h>
    should be
    Code:
    #include <iostream>
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    u can also use the header

    Code:
    #include <iostream.h>
    without,

    Code:
    using namespace std;
    the interesting way out is name the file with extension .C
    mark it, its CAPS "C".

    Hence u can compile that using g++ compiler as discussed b4...

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    when u compile the code as

    Code:
    g++ -o prog prog.C
    there would be some warning messages...so hence disable the warning by using this piece of option along with the g++ command

    Code:
    g++ -o prog prog.C -Wno-deprecated
    and finally,

    Code:
    ./prog
    I hope this will give u a very clear picture...

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    But why would you want to write new code using deprecated features?

    Building in obsolescence before you've even begun is no way to go.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    I appreciate ur thinking...
    BUT, there is nothing wrong in having knowledge of a bit more features supported by g++, in case the codes which are really obsolute but needs to be compiled in g++...hence g++ compiler has a good support for obsolute codes compilation too...

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's good to have knowledge that helps you understand outdated programs. BUT when imparting this knowledge, you should always point out that this knowledge is indeed only for understanding of old programs and not for using in new programs.

    Oh, and don't use a capital C as a file ending for C++ programs, as this trick makes it unportable to systems where the filesystem is case-insensitive - like Windows.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21