Re: newbie linker error - 'undefined reference'
The compiler does not understand what cout and << is.
You forgot to include <iostreams.h>
Matt Miller wrote:
> I want to compile, and then link, even. (Imagine that.) I think my
> basic problem is how to learn what libraries to include on my link command
> line.
>
> Here's my first attempt at building a program from scratch on my slink
> system:
>
> t.cc:
>
> #include <fstream.h>
>
> int main (int argc, char *argv[])
> {
> cout << argv[1];
> return 0;
> }
>
> Makefile:
>
> t: t.o
> t.o: t.cc
>
> Emacs compilation buffer:
>
> make -k
> g++ -c t.cc -o t.o
> cc t.o -o t
> t.o: In function `main':
> t.o(.text+0xd): undefined reference to `cout'
> t.o(.text+0x12): undefined reference to `ostream::operator<<(char const
> *)'
> make: *** [t] Error 1
>
> This is a linker unresolved reference, right? I need to pass a command
> line switch to the linker to tell it the library, right?
>
> Okay, how can I relate a given header (e.g. fstream.h) with the library or
> libraries that house the functions published by the header? Is there a
> ../doc/.. area that I haven't found? Should I use ld to scan all
> library directories searching for functions names?
>
> Thanks,
>
> Matt Miller
>
> -----------------------------------------------------------------------
> 'The number of UNIX installations has grown to 10, with more expected.'
> - The UNIX Programmer's Manual, 2nd Edition, June, 1972
>
> --
> Unsubscribe? mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null
--
____________________________________________________________________________
Shao Zhang - Running Debian 2.1 ___ _ _____
Department of Communications / __| |_ __ _ ___ |_ / |_ __ _ _ _ __ _
University of New South Wales \__ \ ' \/ _` / _ \ / /| ' \/ _` | ' \/ _` |
Sydney, Australia |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.edu.au |___/
_____________________________________________________________________________
Reply to: