0

How do I extend the following program to display basic GUI element Button in Cygwin on Windows?

#include <stdio.h>

int main(int argc, char **argv) {
  printf("Hello, World!\n");
}

And to compile and run.

gcc hello.c -o hello.exe
./hello.exe
  • Wouldn't this question (which is not related to Unix) better asked on StackOverflow or Programmer? – Basile Starynkevitch Nov 9 '15 at 6:28
  • @BasileStarynkevitch Cygwin is technically unix although you are right it is more about c then unix. I have not tried this question on SO, but I feel like it might be closed or more likely put on hold for being either being to broad or narrow. SO is often a little more stringent on questions but I will try it. – William Nov 21 '15 at 16:30
0

You cannot do that without some specific GUI library, since standard C99 or C11 does not define any.

BTW, you should compile with gcc -Wall -g hello.c -o hello.exe ; you really want all warnings and debug info.

You might consider using some cross-platform GUI library GTK or libsdl or (in C++) Qt. You'll need to install it before using it and of course pass additional arguments to gcc (several -I directives before the source file, several -L directives and -l libraries from high-level to low-level). Notice that order of arguments to gcc is important. You may want to use GNU make as your builder, with your own Makefile ...

(I don't know Windows and I recommend Linux; perhaps some system provided Windows GUI library is usable from Cygwin)

Your program will then become event-driven, with the event loop usually provided by the GUI library. It will become much more complex.

You could (instead of a desktop GUI approach) consider making your program some specialized Web server; you'll then use some HTTP server library (I know about libonion, but it probably has not been ported to Windows), and your program would become a Web application usable thru a browser, and should also be event-driven.

  • 1
    you might want to conside targeting mingw instead of cygwin. – Jasen Nov 9 '15 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.