This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Re: Won't compile the simplest of progs.
- To: Daniel Harry Hawson <u7dhh AT dcs.shef.ac.uk>
- Subject: Re: Won't compile the simplest of progs.
- From: Gabriel Galibourg <gabriel AT solfin dot com>
- Date: Thu, 16 Sep 1999 11:47:46 +0200
- CC: cygwin AT sourceware.cygnus dot com
- Organization: Solfin Limited
- References: <199909151131.MAA02157@cedar.dcs.shef.ac.uk>
- Reply-To: gabriel AT solfin dot com
Yes cygwin (well really gcc) compiles C and C++ code, altough I prefer to use gcc when compiling C code and g++ when compiling C++ code (helps the linker get it right).
The problem with your code is that you are using a windows function (getch()) which does not exist in cygwin (or Unix). The 'proper' Unix way to get simple character input would be to put your terminal in non-canonical mode (stty -icanon min 1 time 0), you can do this within a C/C++ program by using ioctl() (but I've never done it under cygwin so I ignore if it works).
So to keep the story short, to get your program to work do the following:
1) remove the #include <conio.h> since cygwin doesn't know about it - you could put the full path to it (in your msdev directories) - but I don't think that would help much
2) change your call to getch() to _getch() - which is the 'real' library function (getch() is merely a #define to it)
3) compile the following way:
g++ -o Progs/key.exe Progs/keypress.cpp -lmsvcrt
You need to link with msvcrt which is where _getch() is defined. You'll also get a warning about the implicit declaration of _getch(), you can always clean this up later by creating you own conio.h with the good stuff in it.
The resulting program works fine under a 'normal' command prompt (cmd.exe) but does not work very well under the cygwin bash .
Gabriel.
> Daniel Harry Hawson wrote:
>
> > I have a 'Progs' folder in my 'cygwin-b20' folder.
> > In 'Progs', I tried to compile a C++ file called 'Keypress.cpp'.
> >
> > > BASH.EXE-2.02$ gcc -o Progs/key.exe Progs/keypress.cpp
> > > Progs/keypress.cpp:1: conio.h: No such file or directory
> > > BASH.EXE-2.02$
> >
> > What am I doing wrong?
> >
> > Here is the contents of 'Keypress.cpp' -
> >
> > > #include <conio.h>
> > > #include <iostream.h>
> > >
> > > int main(void)
> > > {
> > > int c;
> > > c = getch();
> > > while (c != 27) //27 = esc
> > > {
> > > cout<<"pressed :"<<c<<'\n';
> > > c = getch();
> > > }
> > > return 0;
> > > }
> >
> > Will CygWin work with C++ or just C code?
> > How can I get this to work?
> >
> > Thanks.
> >
> > Dan
> > u7dhh@dcs.shef.ac.uk
> >
> > --
> > Want to unsubscribe from this list?
> > Send a message to cygwin-unsubscribe@sourceware.cygnus.com
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com