Search code examples
cmakefilecygwin

Compiling and Distributing C Programs


I just finished a semester up of C programming for a class I'm in, and it has left me with some questions that I was hoping to get answered.

During my class we have been using GCC to compile C programs. This is all good and well, but I have a question about compiling.

What if I wanted to build a C program on Windows? There is no GCC. Is that what Microsoft Visual Studio is for?

Also, what if I wanted to compile a program and distribute it? What would I compile to distribute to other Window's users?

In summary, I know how to write C programs, but I just don't get how you would make a program to give to someone who doesn't have a C compiler and is basically computer dumb.

Thanks in advance, Ryan


Solution

  • Generally you will need to do two things:

    1. Compile your program into a stand-alone executable or binary.

      a. On Windows this would be a win32 executable.

      b. On Linux this would be an elf binary.

    2. Create an installer package for your program.

      a. On Windows you might use NSIS, Microsoft MSI, or InstallShield.

      b. On Linux you would do well to use a packager for the distribution you want to target.

    Anecodtally, it is very easy to utilize Eclipse CDT and NSIS to develop C and C++ software on Windows without needing to pay any license fees.

    Eclipse CDT: http://eclipse.org/cdt/

    Starter Guide: http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx

    NSIS: http://nsis.sourceforge.net/Main_Page

    Note that if you use Visual Studio then you will also need to compile in release mode and distribute the Visual Studio CRT or .NET runtime(s). It depends upon how you link to the standard library provided by your compiler.