From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: c++ include file problems Date: Sun, 18 Jan 1998 15:22:55 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 52 Message-ID: <34C2649F.2648@cs.com> References: <34c24a49 DOT 1579093 AT news1 DOT c2i DOT net> NNTP-Posting-Host: ppp227.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Kim Robert Blix wrote: > > Im having a problem I cant find in any FAQ. > > I have just installed djgpp, and everything seemed to work fine until > i tried to compile a c++ program. It seems to me like the compiler > cant find the c++ include files. I have attached a log of what > happends here, I just want to mention that I have not edited > djgpp.env. Any and all help is appreciated. You're not linking the C++ libraries into your program. It's not enough to include the headers; the compiler must be told where to find the actual code that the headers declare. You may either add "-lgpp" to the end of your command line, or substitute 'gxx' for 'gcc'. The FAQ describes this problem: "undefined reference to ..." in chapters 8.1 and 8.2. The 'readme.1st' file also tells you how to compile C++ programs; evidently you forgot to read that far. Additional comments: > #include > > void main(void) > { > cout << "Hello World"; > } /* main */ void main() is an illegal construct in C and C++. main() must ALWAYS return an integer; else you could cause major problems. This is a rule of ANSI C and any books that tell you otherwise are lying. > e:\djgpp\code>gcc hello.cpp I recommend the following command line: gxx -Wall -O -g -o hello.exe hello.cpp This gives you maximum benefit of gcc's optimizations and warnings, and would have told you about the 'void main' thing. :-) The '-o' option also tells gcc what file to produce as output; otherwise it just makes 'a.exe'. hth -- --------------------------------------------------------------------- | John M. Aldrich | "Autocracy is based on the assumption| | aka Fighteer I | that one man is wiser than a million | | mailto:fighteer AT cs DOT com | men. Let's play that over again, | | http://www.cs.com/fighteer | too. Who decides?" - Lazarus Long | ---------------------------------------------------------------------