6

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.

  • Let's say I developed a simple "Hello,World!"program using a text editor in c.
  • In Ubuntu, I've compiled it using GCC $ gcc -o hello.out -g -Wall -pedantic hello.c
  • I executed it './output.out'
  • And got the result Hello, World!

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

  • installed cygwin
  • In Cygwin, I compiled it using GCC $ gcc -o hello.exe -g -Wall -pedantic hello.c

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

  • In Cygwin, I executed it '$ ./output.exe'
  • And got the result Hello, World!

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!

4
  • You use a compiler designed for Windows, such as Visual Studio. Commented Jul 12, 2016 at 12:27
  • But how do I set up the VS compiler? I read that there is no gcc for Visual Studio
    – Big Dude
    Commented Jul 12, 2016 at 14:30
  • "how do I set up the VS compiler?" - usually you don't need to, VS is a full IDE. You create a project, add your source files, do any other configuration, and click "run" (or "build"). Commented Jul 12, 2016 at 15:10
  • That's correct, but the compiler C++ uses seems to differ from which C uses. I'm not an C++ expert, please don't get me wrong, but if take my code and click "run" to build it, it will cause errors because I implemented a couple of things in a C manner. F.ex. if I use the merge sort and do something like int foo( int p, int r){char arr [ (r-p) +1 ]; } , I'll get an error in C++. I guess I didn't meant it like I wrote it , sorry for that :)
    – Big Dude
    Commented Jul 12, 2016 at 15:24

2 Answers 2

6

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.

1
  • Perfect, that's what I was looking for. Thanks a lot!
    – Big Dude
    Commented Jul 12, 2016 at 15:00
1

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

3
  • Dear @Ishay, unfortunately, your solution didn't work. I installed mingw and compiled my program from within the windows command line using gcc. The error remains the same on other machines. If I try to execute it, it will fail
    – Big Dude
    Commented Jul 12, 2016 at 14:29
  • You accepted the answer that uses mingw what's the difference between that one and what I proposed? Commented Jul 12, 2016 at 15:24
  • No offence, he provided an example which for me was easier to understand. Both of you're right.
    – Big Dude
    Commented Jul 13, 2016 at 8:29

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