Mail Archives: djgpp/1998/01/18/15:30:22
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 <iostream.h>
>
> 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 |
---------------------------------------------------------------------
- Raw text -