From: swarsmatt AT aol DOT com (SWars Matt) Newsgroups: comp.os.msdos.djgpp Subject: Re: C++ undefined referance error Date: 6 Feb 1998 02:52:08 GMT Lines: 28 Message-ID: <19980206025201.VAA00812@ladder03.news.aol.com> NNTP-Posting-Host: ladder03.news.aol.com Organization: AOL http://www.aol.com References: <34DA3361 DOT EBDD575 AT megsinet DOT net> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk >Hello, could someone please tell me why djgpp won't compile this code? > >#include >int main() >{ > cout << "hello world"; > return 0; >} > > I've been compiling C programs for a while now with no problems, but >when I went to try c++ I got two errors: >". . . .ex1.cpp: undefined reference to 'cout'" and >". . . .undefined reference to 'ostream::operator<<(char const *)'" > >I downloaded the c++ libraries again and the c++ executable and made >sure to end my file with *.cpp. Also, I checked the faq but I couldn't >find anything about this. As I said before, it worked fine compiling c >programs. Thanks, Pat > This is a common mistake. You see, including a header just tells the main function that these other functions/classes/whatever exist, basically. They still must be defined. This is where libraries come in. The problem would be that you didn't link the library (-liostr, I think). Alternatively, you could compile with gxx, not gcc, so that the C++ libraries are automatically linked in. Hope that solves your problem!