windows 如何编译C程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/571076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compile a C program?
提问by AngryHacker
I haven't done C in a long time. I'd like to compile this program, but I have no idea how to proceed. It seems like the makefile refers to GCC a lot and I've never used GCC.
好久没做C了 我想编译这个程序,但我不知道如何进行。似乎 makefile 经常提到 GCC,而我从未使用过 GCC。
I just want an executable that will run on windows.
我只想要一个可以在 Windows 上运行的可执行文件。
回答by vladr
You may need to install either cygwin or mingw, which are UNIX-like environments for Windows.
您可能需要安装 cygwin 或 mingw,它们是适用于 Windows 的类 UNIX 环境。
When downloading/installing either cygwin or mingw, you will have the option of downloading and installing some optional features; you will need the following:
在下载/安装 cygwin 或 mingw 时,您可以选择下载和安装一些可选功能;您将需要以下内容:
- gcc (try version 2.x first, not 3.x)
- binutils
- GNU make (or gmake)
- gcc(首先尝试版本 2.x,而不是 3.x)
- 二进制实用程序
- GNU make(或 gmake)
回答by m0j0
If it requires gcc and you want it to run on Windows, you could download Cygwin.
如果它需要 gcc 并且您希望它在 Windows 上运行,则可以下载 Cygwin。
That's basically an emulator for GNU/Linux type stuff for Windows. It works with an emulation DLL.
这基本上是用于 Windows 的 GNU/Linux 类型东西的模拟器。它与仿真 DLL 一起使用。
回答by Dima
In order to compile this program you need a C compiler. It does not have to be gcc, although you are already given a makefile set up to use gcc. The simplest thing for you to do would be the following:
为了编译这个程序,你需要一个 C 编译器。它不必是 gcc,尽管您已经获得了一个设置为使用 gcc 的 makefile。您要做的最简单的事情如下:
- Install cygwin
- Open the cygwin command prompt
- go into the directory where you have your makefile
- type 'make'
- That should compile your program
- 安装cygwin
- 打开 cygwin 命令提示符
- 进入你的makefile所在的目录
- 输入“制作”
- 那应该编译你的程序
If you are not comfortable with using command line tools then you can download the free versionof MS Visual Studio and import the source files into a new Visual Studio project. This way you would not need to install cygwin and use gcc, but you would need to know how to create projects and run programs in Visual Studio.
如果您不习惯使用命令行工具,那么您可以下载免费版本的 MS Visual Studio 并将源文件导入到新的 Visual Studio 项目中。这样你就不需要安装 cygwin 和使用 gcc,但你需要知道如何在 Visual Studio 中创建项目和运行程序。
回答by Yes - that Jake.
回答by Greg Hewgill
If it's reasonably portable C code (I haven't looked at it), then you may be able to just ignore the included Makefile and feed the source into whatever compiler you do want to use. What happens when you try that?
如果它是相当可移植的 C 代码(我没有看过它),那么您可以忽略包含的 Makefile 并将源代码提供给您想要使用的任何编译器。当你尝试时会发生什么?
回答by ctuffli
Dev-C++provides a simple but nice IDE which uses the Mingw gcc compiler and provides Makefile support. Here are the steps I used to build the above code using Dev-C++ (i.e. this is a "how-to")
Dev-C++提供了一个简单但不错的 IDE,它使用 Mingw gcc 编译器并提供 Makefile 支持。以下是我使用 Dev-C++ 构建上述代码的步骤(即这是一个“操作方法”)
After downloading the source zip from NIST, I
从 NIST 下载源 zip 后,我
- downloaded and installed the Dev-C++ 5 beta 9 release
- created a new empty project
- added all the .c files from sts-2.0\src
- 下载并安装了 Dev-C++ 5 beta 9 版本
- 创建了一个新的空项目
- 从 sts-2.0\src 添加了所有 .c 文件
Then under Project Options
然后在项目选项下
- added
-lm
in the Linker column under Parameters - added
sts-2.0\include
to the Include Directories in Directories - set the Executable and Object directories to the
obj
directory under the Build Options
- 添加
-lm
在参数下的链接器列中 - 添加
sts-2.0\include
到在目录中包含目录 - 将 Executable 和 Object 目录设置
obj
为 Build Options 下的目录
and then hit OK to close the dialog. Go to Execute > Compile and let it whirl. A minute later, you can find the executable in the sts-2.0\obj
directory.
然后点击确定关闭对话框。转到执行> 编译并让它旋转。一分钟后,您可以在sts-2.0\obj
目录中找到可执行文件。
回答by David Cournapeau
First, there is little chance that a program with only makefiles will build with visual studio, if only because visual studio is not a good C compiler from a standard POV (the math functions in particular are very poorly supported on MS compilers). It may be possible, but it won't be easy, specially if you are not familiar with C. You should really stick to the makefiles instead of trying to import the code in your own IDE - this kind of scienfitic code is clearly meant to be compiled from the command line. It is a test suite, so trying things randomly is NOT a good idea.
首先,只有 makefile 的程序用 Visual Studio 构建的可能性很小,这仅仅是因为 Visual Studio 不是来自标准 POV 的好的 C 编译器(尤其是数学函数在 MS 编译器上的支持非常差)。这可能是可能的,但这并不容易,特别是如果您不熟悉 C。您应该真正坚持使用 makefile,而不是尝试在您自己的 IDE 中导入代码 - 这种科学代码显然是为了从命令行编译。这是一个测试套件,所以随机尝试不是一个好主意。
You should use mingw + msys to install it: mingw will give you the compilers (gcc, etc...) and msys the shell for the make file to run correctly. Contrary to one other poster, I would advise you against using gcc 2 - I don't see any point in that. I routinely use gcc 3 (and even 4) on windows to build scientific code, it works well when the code is unix-like (which is the standard platform for this kind of code).
您应该使用 mingw + msys 来安装它:mingw 将为您提供编译器(gcc 等...),而 msys 将为 make 文件正确运行提供 shell。与另一张海报相反,我建议您不要使用 gcc 2 - 我认为这没有任何意义。我经常在 Windows 上使用 gcc 3(甚至 4)来构建科学代码,当代码类似于 unix(这是此类代码的标准平台)时,它运行良好。