can't find library for iostream

Discussion in 'C++' started by Victor Bazarov, Aug 30, 2004.

  1. Sigmund Skjelnes wrote:
    > Trying to get a simple cpp program to compile, I'd got the linker
    > complaining it could'nt find eiter cout nor endl or other object which
    > belong to iostream. I'd had to use stdiolib to get the program working.
    > I'd have attached the source code, [...]


    Please don't post attachments. Copy and paste the code into the message
    if you have to send it. It is likely, though, that if it _compiles_, we
    cannot help you any more. Linking is not defined by the language itself.

    > Do anybody have a clue why the library is missing? [...]


    Because you didn't tell your compiler where to find the library, maybe?

    Ask in a newsgroup that deals with your compiler or with your OS. They
    might know more about the compiler options (switches) you need to provide
    or the libraries you need to list in the link command line.
    <offtopic> Example: often programs on UNIX don't link unless you mention
    the math library using the -lm switch</offtopic>

    Victor
     
    Victor Bazarov, Aug 30, 2004
    #1
    1. Advertising

  2. Victor Bazarov

    Mike Wahler Guest

    "Sigmund Skjelnes" <> wrote in message
    news:41333dd4$...
    > Hi!
    > Trying to get a simple cpp program to compile, I'd got the linker
    > complaining it could'nt find eiter cout nor endl or other object which
    > belong to iostream. I'd had to use stdiolib to get the program working.
    > I'd have attached the source code, some of it is Norwegian, but I'd
    > think it will make sense anyway.
    >
    > Do anybody have a clue why the library is missing? The code compiled ok
    > because the .h file is there, but the linker is stopping with the
    > message "unassigned reference to cout...".
    >
    > Cincerely,
    > Sigmund
    >



    ----------------------------------------------------------------------------
    ----


    > // #include<iostream.h>


    The C++ header which declares 'cout' et.al. is <iostream> , with no '.h'
    The header which declares 'endl' is <ostream>

    All the standard library names (except macros) are in namespace
    'std'.

    #include <iostream>
    using std::cout;

    #include <ostream>
    using std::endl;

    But this doesn't explain why you get a successful compile
    but a failed link. (Your compile was successful because
    apparently your compiler recognizes the old, pre-standard
    C++ without namespaces.)

    I'm guessing that perhaps you're running your C++ compiler
    in 'C mode'. Double check that.

    If you're still stuck, you'll need to consult support resources
    for your compiler (web site, phone support, newsgroups for
    your compiler, etc.)

    -Mike
     
    Mike Wahler, Aug 30, 2004
    #2
    1. Advertising

  3. Hi!
    Trying to get a simple cpp program to compile, I'd got the linker
    complaining it could'nt find eiter cout nor endl or other object which
    belong to iostream. I'd had to use stdiolib to get the program working.
    I'd have attached the source code, some of it is Norwegian, but I'd
    think it will make sense anyway.

    Do anybody have a clue why the library is missing? The code compiled ok
    because the .h file is there, but the linker is stopping with the
    message "unassigned reference to cout...".

    Cincerely,
    Sigmund

    // #include<iostream.h>
    #include<stdio.h>

    static int idcnt; // se T

    class T
    {
    public:
    //static int idcnt; // denne liker ikke linkeren
    int id;

    int number;


    T( int n ){
    number = n;
    id = idcnt++;
    printf( "Constructor kalt %d\n", id );
    }

    T( const T &t ){
    number = t.number;
    id = idcnt++;
    printf( "Kopierings-constructor: %d\n", id );
    }

    ~T(){
    printf( "Destructor kalt: %d\n", id );
    }

    void setNumber( int n ){
    number = n;
    }
    };

    void setNumber( T t, int n );
    void setPNumber( T *t, int n );

    // finner iostream.h, men ikke det tilhørende bibloteket

    void main(){

    T t(-1);
    // cout << "Constructor setter number til -1 " << t.number << endl;
    printf( "Constructor setter number til -1: %d\n", t.number );

    setNumber( t, 4 );
    // cout << "Instans gitt ved referanse endrer ikke instansen ";
    // cout << t.number << endl;
    printf( "Instans gitt ved referanse endrer ikke instansen: %i\n", t.number );

    setPNumber( &t, 4 );
    // cout << "Instans gitt med peker endrer instansen: ";
    // cout << t.number << endl;
    printf( "Instans gitt med peker endrer instansen: %i\n", t.number );

    t.setNumber( 6 );
    //cout << "Medlemsfunksjon endrer instansen " << t.number << endl;
    printf( "Medlemsfunksjon endrer instansen %i\n", t.number );
    }

    void setNumber( T t, int n ){
    t.number = n;
    printf("Her kalles kopi-constructor for å kopiere instansen\n");
    }

    void setPNumber( T *t, int n){

    t->number = n;
    }
     
    Sigmund Skjelnes, Aug 30, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Tiger
    Replies:
    10
    Views:
    5,649
  2. eric

    can't find iostream.h

    eric, May 17, 2004, in forum: C++
    Replies:
    1
    Views:
    2,677
    Victor Bazarov
    May 18, 2004
  3. ai@work
    Replies:
    9
    Views:
    562
    Ron Natalie
    Dec 16, 2004
  4. S. Nurbe

    iostream + iostream.h

    S. Nurbe, Jan 14, 2005, in forum: C++
    Replies:
    7
    Views:
    794
    red floyd
    Jan 15, 2005
  5. red floyd
    Replies:
    3
    Views:
    551
    Dietmar Kuehl
    Mar 8, 2005
Loading...

Share This Page