www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/23/10:12:33

Date: Wed, 24 Apr 1996 00:06:05 +1000
From: root <root AT linuxbox DOT nse DOT com DOT au>
Message-Id: <199604231406.AAA07430@linuxbox.nse.com.au>
To: m9501470 AT cse DOT rmit DOT EDU DOT AU
CC: djgpp AT delorie DOT com
Subject: Can't compile C++ program with gcc
In-Reply-To: <30872242@toto.iv>
Reply-To: naderr AT topaz DOT cqu DOT edu DOT au

m9501470 AT cse DOT rmit DOT edu DOT au writes:
 > 
 > #include <iostream.h>
 > 
 > main()
 > {
 >   cout << "hello, world." << endl;
 >   return 0;
 > }
 > 
 > I've currently download a DGJPP C++ 2.7.2 compiler and installed the package 
 > according to the instruction, when I compiled the above program with 
 > 
 >   gcc -Wall -o try try.cc 
 > or
 >   cc1plus -Wall -o try try.cc
 > 
 > I have obtained the following errors:
 > 
 > try.cc(.text+0x1a): undefined reference to `endl(ostream &)'
 > try.cc(.text+0x24): undefined reference to `cout'
 > try.cc(.text+0x29): undefined reference to `ostream::operator<<(char const *)'
 > try.cc(.text+0x34): undefined reference to `ostream::operator<<(ostream &(*)(ostream &))'
 > 
 > Can anyone suggest what do I need to do to get rid of above errors. Thanks in 
 > advance.
 > 


from my linuxbox which is the same diff ...

[241][ root AT linuxbox: ~/tmp/
# v
total 37
-rwxr-xr-x   1 root     root        35273 Apr  9 01:44 hello*
-rw-r--r--   1 root     root          102 Apr  9 01:36 hello.C
[242][ root AT linuxbox: ~/tmp/
# rm hello
hello
[243][ root AT linuxbox: ~/tmp/
# gcc -Wall -o hello hello.C
/tmp/cca074071.o: In function `main':
/tmp/cca074071.o(.text+0x5): undefined reference to `endl(ostream &)'
/tmp/cca074071.o(.text+0xf): undefined reference to `cout'
/tmp/cca074071.o(.text+0x14): undefined reference to `ostream::operator<<(char const *)'
/tmp/cca074071.o(.text+0x1f): undefined reference to `ostream::operator<<(ostream &(*)(ostream &))'
[244][ root AT linuxbox: ~/tmp/


What you need to do _if_ using gcc instead of g++ ( gxx for djgpp )

[247][ root AT linuxbox: ~/tmp/
# gcc -Wall -o hello hello.C -lg++
[248][ root AT linuxbox: ~/tmp/


which is linking with libg++ (libgpp for djgpp )

thus you should try ...

gcc -Wall -o try try.cc -lgpp

but if you wish not to bother with the -lgpp
just use gxx instead 


hope this helps,

ps: ... Hmmm It's in the faq I believe :)


Cheers,

		Rob

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019