Thread: linux gcc

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    7

    linux gcc

    hi someone knows why my gcc whe i compile my program usin iostream.h it gives me a lot of errors about the iostream header ......

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    It depends on the errors, but maybe it should be <iostream> without the '.h':

    http://www.cplusplus.com/doc/ansi/hfiles.html

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Posting code and error messages would be a good idea...
    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.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    7
    here's the code:

    Code:
    #include <iostream>
    
    using namespace std;
    
    main(){
           int k;
           cout << k;
           return 0;
     }
    and here's the gcc output:


    /tmp/cccD88Yz.o: In function `main':
    /tmp/cccD88Yz.o(.text+0x1e): undefined reference to `std::cout'
    /tmp/cccD88Yz.o(.text+0x23): undefined reference to `std::basic_ostream<char, st
    d::char_traits<char> >:perator<<(int)'
    /tmp/cccD88Yz.o: In function `__static_initialization_and_destruction_0(int, int
    )':
    /tmp/cccD88Yz.o(.text+0x50): undefined reference to `std::ios_base::Init::Init[i
    n-charge]()'
    /tmp/cccD88Yz.o: In function `__tcf_0':
    /tmp/cccD88Yz.o(.text+0x7f): undefined reference to `std::ios_base::Init::~Init
    [in-charge]()'
    /tmp/cccD88Yz.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Try
    g++ prog.cpp

    Not
    gcc prog.cpp

    That is, use the C++ compiler and not the C compiler to compile your code.
    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.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    7

    Thumbs up

    thanks that was useful........

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    24
    Code:
    #include <iostream>
    
    using namespace std;
    
    main(){
           int k;
           cin >> k;
           cout << k;
           return 0;
     }
    and with linux use g++ prog.cc

    or you can always use the emacs complier (which is harder to understand) but pico is easy and basic to use.

  8. #8
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() {  // need to be returnign something from main.
           int k = 0 ; // gota intialize  k to be something
           cout << k;
           return 0;
     }
    Main things i see wrong are
    A: You arn't returning something from main, and it must be an int.
    B: k was allocated but not initialized. so what ever memory k points to, it has soem random crap from what ever was there before

  9. #9
    Registered User
    Join Date
    Oct 2003
    Posts
    7
    Iamien :you're right something i forgot at time to post the code i didn't copy the initialization...

  10. #10
    Registered User
    Join Date
    Oct 2003
    Posts
    24
    my code was basic and simplistic and it allowed for the user to enter in what value they wanted for K.. But if you are not allowing for a user to define their own value - then make sure that you have intialized the value first.

    Code:
    #include <ostream>
    
    using namespace std;
    
    int main() {  // need to be returning something from main.
           int k = 0 ; // got to intialize  k to be something
           cout << k; // output of k
           return 0; // program ended successfully
     }
    If you are using just output statements - you can make your program smaller and faster by going with just an ostream instead of iosteam..

    A lot of programs for PDA's and Pagers etc (small hand held devices) use istream and ostream depending on their use.

    For a program as small as the one that we have hashed and rehased then it won't make the slightest difference. But make a large program and test it out.

    Be sure to 'comment' (i.e // output of k) your work to death - it will help in the long run. It will make the program easy to read and understand and definately easier to transfer into larger projects.

  11. #11
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    Originally posted by NIM
    or you can always use the emacs complier (which is harder to understand) but pico is easy and basic to use.
    I really hate to nit pick, but just to alieviate any potential confusion: To my knowledge, neither Emacs or pico are/have a compiler. They just use gcc/g++.

    ~arker

  12. #12
    Registered User
    Join Date
    Oct 2003
    Posts
    24
    Originally posted by Arker
    I really hate to nit pick, but just to alieviate any potential confusion: To my knowledge, neither Emacs or pico are/have a compiler. They just use gcc/g++.

    ~arker
    yes

    emacs and pico are the programs that you write the code in.. and gcc/g++ are the compilers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Port app from Windows to Linux
    By BobS0327 in forum Linux Programming
    Replies: 12
    Last Post: 02-12-2006, 02:35 AM
  2. Replies: 3
    Last Post: 10-29-2003, 09:39 AM
  3. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM
  4. programming linux with gcc, emacs, and makefiles
    By Captain Penguin in forum Linux Programming
    Replies: 1
    Last Post: 11-02-2002, 12:04 PM
  5. Linux GCC
    By Gcc_Confused in forum Linux Programming
    Replies: 4
    Last Post: 06-05-2002, 01:03 PM