gcc produces foo.exe, not foo

Stephen Vance vance@deneb.com
Wed Sep 23 19:20:00 GMT 1998

Arne Glenstrup wrote:

> Hello,
> Apologies if this question has been answered many times before, but I
> didn't seem to be able to find it in the mailing list archives via the
> search function.
> The problem is that it seems that when running
>   gcc -o foo foo.c
> it produces not a file named foo, but a file named foo.exe. This has
> caused me problems when writing a Makefile somewhat like
>   bar: foo.c
>           gcc -o foo foo.c
>           mv foo bar
> because it complains when trying to mv file foo.
> What is the standard way of circumventing this problem? Simply writing
>           mv foo.exe bar.exe
> is not a full solution, because that is not portable. Is it necessary to
> write some autoconf stuff to check what the extension of the executable
> resulting from calling gcc is?
> Thanx,
> -- Arne.
> -
> For help on using this list (especially unsubscribing), send a message to
> "gnu-win32-request@cygnus.com" with one line of text: "help".

We tend to deal with this in the following way.

1) Define an environment variable to contain some platform identifier (e.g.
2) Create a file like the following called Cygwin32.mk


The Unix equivalent (e.g. Sun5.mk) might be


3)  Create your makefiles to include the platform makefile and use its

include $(ARCH).mk

bar$(EXE): foo.c
    gcc -o foo$(EXE) foo.c
    mv foo$(EXE) bar$(EXE)

Obviously, there are improvements to be applied in the use of make, the
$(ARCH).mk files can be put in a central location, you can do similar things
with compiler and linker flags, provide a means for directory-specific
platform settings, etc. to extend this to a full-fledged make environment,
but this is the basic technique.

Stephen Vance                           |  http://www.deneb.com
Deneb Robotics, Inc.                    |  mailto:vance@deneb.com
5500 New King Street                    |  Phone: (248) 267-9696
Troy, MI 48098-2615                     |  Fax:   (248) 267-8585

What is done well is done quickly enough. -Augustus Caesar

For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

More information about the Cygwin mailing list