在 Windows 中使用 Makefile 编译 C 源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3059400/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:40:26  来源:igfitidea点击:

Compiling C Source with Makefile in Windows

cwindowsmakefile

提问by humoeba

I'm trying to compile a downloaded program in Windows. The program is usually run in Linux, but is programmed to also run in Windows (the code has #if defined(_WIN32)'s in it, and claims to work with borland free tools). When I try to use make from the command line, it tells me "Incorrect command line argument: -C". In the makefile, there are many lines that say "make -C" followed by a directory name. Does this syntax not work in Windows? What is a correct way to do this? Is there any way to compile this for native use in Windows with this makefile?

我正在尝试在 Windows 中编译下载的程序。该程序通常在 Linux 中运行,但被编程为也可以在 Windows 中运行(代码中包含 #if 定义(_WIN32),并声称可以使用 borland 免费工具)。当我尝试从命令行使用 make 时,它​​告诉我“命令行参数不正确:-C”。在 makefile 中,有很多行说“make -C”后跟目录名。此语法在 Windows 中不起作用吗?这样做的正确方法是什么?有什么办法可以用这个 makefile 在 Windows 中编译它以供本机使用吗?

回答by Michael Burr

Windows itself doesn't come with a make utility. Microsoft does have a 'make' utility that comes with their development tools (such as Visual Studio, the Platform SDK, or the Windows Driver Kit) but it's called nmake.

Windows 本身不附带 make 实用程序。Microsoft 确实有一个随其开发工具(例如 Visual Studio、Platform SDK 或 Windows Driver Kit)附带的“make”实用程序,但它被称为nmake.

You probably need GNU make to process those makefiles. you can get a copy for Windows here:

您可能需要 GNU make 来处理这些 makefile。您可以在此处获取适用于 Windows 的副本:

However, if the makefile isn't written to be able to be run on Windows, it'll probably not work well. You'll also need to make sure you have whatever other development tools the makefile calls upon (maybe the Borland compiler or GCC), and there may be other configuration that needs to be done specific to the project you want to build. It's probably not a matter of just having the correct make utility.

但是,如果 makefile 没有编写为能够在 Windows 上运行,则它可能无法正常工作。您还需要确保您拥有 makefile 调用的任何其他开发工具(可能是 Borland 编译器或 GCC),并且可能需要针对您要构建的项目进行其他配置。这可能不仅仅是拥有正确的 make 实用程序的问题。

回答by Peter Miehle

-C is "change working directory" only for the gmake command (from the GNU package). You should take a look in the manual for your Make-Utility and see, wheather it supports something ?quivalent.

-C 是仅用于 gmake 命令(来自 GNU 包)的“更改工作目录”。你应该看看你的 Make-Utility 的手册,看看它是否支持某些东西?等效的。

Peter

彼得

回答by Roman A. Taycher

Are you using cygwin? Are there any instructions for installing on windows(perhaphs in a README file)?

你用的是cygwin吗?是否有在 Windows 上安装的任何说明(可能在 README 文件中)?