1

I am trying to get compile some C code from within Cygwin on 64-bit Windows and call the executable using some parameters. The compilation goes through fine (the Makefile is below). But when I run the executable, I get the error cannot execute binary file.

A quick shows that indeed the binary is built for Linux.

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x7d39e30cb249d2047815de23a9df33fccf91a58f, not stripped

How can I change the Makefile so that it compiles for Windows?


Here is the Makefile

.SUFFIXES: .c .u
CC= gcc

CFLAGS = -g -Wall -O3 -DHAVE_INLINE -DGSL_RANGE_CHECK_OFF
# LDFLAGS = -lm -lgsl -latlas -lgslcblas
LDFLAGS = -lm -lgsl -lgslcblas
# LDFLAGS = -lm -lgsl -latlas -lcblas
LOBJECTS= a.o b.o c.o 
LSOURCE= a.c b.c c.c 

windows: $(LOBJECTS)
    $(CC) $(LOBJECTS) -o stm $(LDFLAGS)

clean:
    -rm -f *.o

1 Answer 1

4

cygwin is 32 bits, not 64 bits. This is the error you get when trying to run a 64 bit program in a 32 bit environment.

edit: Oh, and you can't compile C for Windows from inside cygwin. There are C compilers for Windows, I know little about them.

Sign up to request clarification or add additional context in comments.

1 Comment

Or the MinGW fork MinGW-w64, which also has 64bit support.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.