Big Dude
Big Dude

Reputation: 264

How to create an executable C file for Windows

I know this question has been asked several times and I took a look at many of them like

Unfortunately, none of them worked for me.

My situation

I've installed Ubuntu and Windows on my Notebook.

What I tried

So I kind of cross-developed here. I switched to Windows and kept going.

Now, I try to make it an executable file in order to run it on Windows. I know Windows can't handle '$ ./output.out' , alright, let's make it an executable then.

Under Windows, I've

Note: I wrote hello.exe instead of hello.out or hello.c

Note: At this point, it even works with my Shell under Windows because I installed Cygwin and set up my PATH etc. This means I can open my command line, go to the directory in which 'hello.exe' is located and execute it by typing '> hello.exe'

I thought that would be it, so I took hello.exe' and moved it to another notebook (not my local machine). I tried to execute it but it didn't work.

At first, I got an cygwin1.dll missing message. After fixing it, another error appears.

What I'm trying to accomplish

To make a long story short: The reason I wrote so much is that I want to give you a detailed look of my situation.

Basically, I'm trying to create an executable c file, which any Windows User could execute without having any development tools.

In Eclipse and Java, you could simply export your program making it a runnable -jar file. All the User has to do is install the latest Java SE version to get it running.

Additionally, I tried to compile my program in Visual Studio but that didn't work either.

Any suggestions? Thanks a lot!

Upvotes: 6

Views: 28755

Answers (2)

matzeri
matzeri

Reputation: 8496

cygwin gcc produce an executable linked to the cygwin1.dll. So it is not usable without that.

gcc  hello.c -o hello-cygwin.exe

$ ldd hello-cygwin.exe
        ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x77bd0000)
        kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77ab0000)
        KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefdc60000)
        SYSFER.DLL => /cygdrive/c/Windows/System32/SYSFER.DLL (0x75650000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)

If you need a standalone program, a solution is to use the mingw compiler (it is available on cygwin as cross compiler to windows)

$ x86_64-w64-mingw32-gcc.exe hello.c -o hello-mingw64.exe

$ ldd hello-mingw64.exe
        ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x77bd0000)
        kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77ab0000)
        KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefdc60000)
        SYSFER.DLL => /cygdrive/c/Windows/System32/SYSFER.DLL (0x75650000)
        msvcrt.dll => /cygdrive/c/Windows/system32/msvcrt.dll (0x7fefdf40000)

You can move the resulting program on another windows machine that don't have cygwin installed.

Upvotes: 6

Ishay Peled
Ishay Peled

Reputation: 2868

You should use mingw which is the gcc port for windows instead of gcc under cygwin. You can get it here.

Upvotes: 1

Related Questions