0

I'm just starting with C and installed Cygwin with GCC compiler on Windows. I tried running this Hello World program.

#include <stdio.h>

int main(void)
{

    //fflush(stdout);
    //setlinebuf(stdout);
    //setbuf(stdout, 0);
    printf("Hello World!\n");
    return 0;
}

The code compiles fine but when I try running it with ./ there is no output. I have tried to fix it using the commented lines (obviously I uncommented before running) but still had no output.

8
  • 4
    Show the command you use to compile and the command you use to run; it is likely there is something wrong with one of those two as the code itself looks fine.
    – R_Kapp
    Feb 10, 2016 at 15:43
  • try this as first instruction in your main function: setvbuf(stdout, NULL, _IONBF, 0);
    – Djee
    Feb 10, 2016 at 15:56
  • The command I use to compile is gcc HelloWorld.c then I run a.exe in Command Line or ./a.exe in Cygwin. I tried setvbuf(stdout, NULL, _IONBF, 0); but it didn't work either.
    – Brecchs
    Feb 10, 2016 at 16:14
  • Can it be that you edit one source file, but compile and run another? Try to do a syntax error whether it breaks the compilation.
    – dmi
    Feb 10, 2016 at 16:25
  • Hmm. I think you have something pretty strange going on. Try this from bash (in cygwin): gcc -oa.exe && ./a.exe
    – user590028
    Feb 10, 2016 at 16:37

2 Answers 2

1

Name your source code file hello.c. In Cygwin bash shell, go to the directory where the source file hello.c is. Run gcc -o hello.exe hello.c. This will produce the executable hello.exe in the same directory. Then run ./hello.

Hope this helps.

1

this may be due to dll missing

add the cygwin dlls in your path, i.e.

d:\cygwin1.7.9[1]\cygwin\bin\
1
  • Correct. It is either the absence or presence of one of Cygwin's DLLs. In my case, i run the gcc command in a directory where I had some of Cygwin's DLLs copied over because I was trying to debug a JNI issue and I had to copy the DLLs into the folder for Intellij IDE to partially work. Thanks to this answer. I simply mkdir xxx; cp app.c xxx; and then do my gcc in that new folder.
    – daparic
    Jun 6, 2020 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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