Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cygwin to Compile a C program; Execution error

Tags:

c

gcc

cygwin

I'm enrolled in a masters computer science course. The course is using C and the instructor wants us to use Cygwin to compile programs if we are using windows.

I've downloaded and installed Cygwin and I've ensured that I've installed the GCC compiler.

But I don't know where to go from here. I need to compile a single source file that has a basic include.

#include <stdio.h> 

Lets assume the file is on my desktop (it is not, but for the sake of argument). How do I navigate to the desktop from the bash shell? I assume once I've navigated to the correct location in bash, I simply execute:

gcc myProgram.c -o myProgram

Update: Following different instructions posted below, I was able to compile the program; I thank you for that. But when I execute the resulting binary I get the following. How can I compile or execute this program so I don't get the error? Again, thank you.

This application has failed to start because cygwin1.dll was not found. Re-installing the application may fix this problem.

like image 444
Frank V Avatar asked Jun 18 '09 16:06

Frank V


2 Answers

when you start in cygwin, you are in your $HOME, like in unix generally, which maps to c:/cygwin/home/$YOURNAME by default. So you could put everything there.

You can also access the c: drive from cygwin through /cygdrive/c/ (e.g. /cygdrive/c/Documents anb Settings/yourname/Desktop).

like image 193
David Cournapeau Avatar answered Oct 19 '22 23:10

David Cournapeau


Regarding your updated question about the missing cygwin1.dll.

From the Cygwin terminal check,

ls /usr/bin/cygwin1.dll

If it is not present (I doubt that), your installation is not properly done.

Then, check your path with,

echo $PATH

This will give : separated list of paths. It MUST contain /usr/bin. If you find that missing add it with,

export PATH=/usr/bin:$PATH

Finally,

  • I hope you are using Cygwin from the cygwin terminal (the little green+black icon installed with Cygwin), or MinTTY (if you installed that).
  • And, you have not moved the compiled EXE to a different machine which does not have Cygwin installed (if you do that, you will need to carry the cygwin1.dll to that machine -- keep it in the same folder as the compiled EXE).
like image 9
nik Avatar answered Oct 19 '22 22:10

nik