By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

can't find library for iostream

P: n/a
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;
}

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 22 '05 #2

P: n/a

"Sigmund Skjelnes" <sk******@robin.no> wrote in message
news:41********@news.broadpark.no...
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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.