简体   繁体   English

编译和分发C程序

[英]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. 我刚刚完成了所学课程的C编程学期,这给我留下了一些我希望得到答案的问题。

During my class we have been using GCC to compile C programs. 在我上课时,我们一直在使用GCC来编译C程序。 This is all good and well, but I have a question about compiling. 这一切都很好,但是我有一个关于编译的问题。

What if I wanted to build a C program on Windows? 如果我想在Windows上构建C程序怎么办? There is no GCC. 没有GCC。 Is that what Microsoft Visual Studio is for? 那是Microsoft Visual Studio的目的吗?

Also, what if I wanted to compile a program and distribute it? 另外,如果我想编译程序并分发该怎么办? What would I compile to distribute to other Window's users? 我将编译什么以分发给其他Window用户?

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. 总而言之,我知道如何编写C程序,但是我不了解如何编写一个程序来提供给没有C编译器并且基本上是计算机傻瓜的人。

Thanks in advance, Ryan 在此先感谢,瑞安

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. 在Windows上,这将是Win32可执行文件。

    b. On Linux this would be an elf binary. 在Linux上,这将是一个elf二进制文件。

  2. Create an installer package for your program. 为您的程序创建一个安装程序包。

    a. 一种。 On Windows you might use NSIS, Microsoft MSI, or InstallShield. 在Windows上,您可以使用NSIS,Microsoft MSI或InstallShield。

    b. On Linux you would do well to use a packager for the distribution you want to target. 在Linux上,最好将打包程序用于要定位的发行版。

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和NSIS在Windows上开发C和C ++软件非常容易,无需支付任何许可费用。

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

Starter Guide: http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx 入门指南: http : //www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx

NSIS: http://nsis.sourceforge.net/Main_Page 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). 请注意,如果您使用Visual Studio,则还需要在发布模式下进行编译并分发Visual Studio CRT或.NET运行时。 It depends upon how you link to the standard library provided by your compiler. 这取决于您如何链接到编译器提供的标准库。

you can get GCC for windows.... 您可以为Windows获取GCC。...

but, Visual Studio is probably a better choice. 但是,Visual Studio可能是一个更好的选择。

Once you have built it, you can use something like Wix or InnoSetup to make an install program for it. 构建完成后,可以使用Wix或InnoSetup之类的工具为其制作安装程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM