Subject: Re: Won't compile the simplest of progs.
From: Gabriel Galibourg <[email-masked]>
To: Daniel Harry Hawson <[email-masked]>
Cc: [email-masked]
Date: Thu, 16 Sep 1999 11:47:46 +0200

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
> > [email-masked]
> >
> > --
> > Want to unsubscribe from this list?
> > Send a message to [email-masked]

--
Want to unsubscribe from this list?
Send a message to [email-masked]