【问题标题】:How to make 'make' work with mingw32 on Windows 7如何使“make”在 Windows 7 上与 mingw32 一起工作
【发布时间】:2013-09-16 22:02:02
【问题描述】:

我对 C 和编程很陌生,所以我希望你们有一点耐心。 但是,我尝试尽可能准确地描述我的问题。 我在我的 Windows 7 计算机上使用 mingw32,我刚刚了解了“make”。 我已经编写了一些源代码文件和一个 Makefile。我想要的是 Makefile 编译我的源代码 int 目标代码,然后将其链接到一个可执行文件 (我想这对专业人士来说并不疯狂)。

这是我的代码:

first.c:

#include<stdio.h>
#include"second.h"
int main()
{
float x = 12.0;
printf("Result is: %.2f\n",go_to_the_other(x));
return 0;
}

秒.h

float go_to_the_other(float f);

秒.c

float go_to_the_other(float f)
{
float calc = f + 10;
return calc;
}

Makefile 是(是的,我只使用了标签):

second.o: second.c second.h
        gcc   -c   second.c
first.o:    first.c
        gcc   -c   first.c
first:   first.o  second.o
        gcc first.o second.o  -o first

这只是一个简单的例子,但它几乎描述了我的问题。 我将所有文件都放在同一个目录中,我使用命令行:

mingw32-make first

但我没有编译我的文件,而是只收到消息:

cc  first.c -o first
process_begin: CreateProcess(NULL, cc first.c -o first, ...) failed
make (e=2): The system cannot find the file specified.
<builtin>: recipe for target 'first' failed
mingw32-make: ***[first] Error 2

我想这可能真的很愚蠢,但我就是想不通 我做错了什么。我真的很感激这方面的任何帮助。 非常感谢您。

【问题讨论】:

  • 这很奇怪。它正在执行构建first 的命令,这些命令甚至不在您的makefile 中。它似乎正在为 c 文件的 make 规则选择默认值。您显示的 makefile 和源代码是否都在同一个文件夹中,并且没有其他 makefile 存在?文件名为makefile 还是Makefile?另外,我假设您输入的是 mingw32-make 而不是 mingw32 -make

标签: c makefile mingw32


【解决方案1】:

所以我去尝试了它......它适用于我在 Win7 机器上使用 MinGW-4.7.1....我想知道是否让它拾取环境变量或类似的东西。

尝试验证 make 和 gcc 的版本是否符合您的期望

mingw32-make -v gcc -v mingw32-gcc -v

也试试这个makefile,看看会发生什么。

CC = mingw32-gcc

second.o: second.c second.h
    $(CC)   -c   second.c
first.o:    first.c
    $(CC)   -c   first.c
first:   first.o  second.o
    $(CC) first.o second.o  -o first

注意将空格转换为制表符!

并通过编译

mingw32-make SHELL=cmd.exe 先

看看会发生什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 2022-12-06
    • 2014-06-15
    • 2014-11-11
    • 2012-06-14
    相关资源
    最近更新 更多