简体   繁体   English

如何在Windows 7上使用mingw32进行'make'工作

[英]How to make 'make' work with mingw32 on Windows 7

I'm pretty new to C and to programming so I hope you guys have a little patience. 我对C和编程还很陌生,所以我希望你们有一点耐心。 However I try to describe my problem as precise as possible. 但是,我尝试尽可能精确地描述我的问题。 I'm using mingw32 on my Windows 7 computer and I just learned about 'make'. 我在Windows 7计算机上使用mingw32,而我刚刚了解了“ make”。 I have written some source-code files and a Makefile. 我已经写了一些源代码文件和一个Makefile。 What I want is, that the Makefile compiles my source-code int object code and then link it together to one executable (I guess that's nothing wild for a pro). 我想要的是,Makefile编译我的源代码int目标代码,然后将其链接到一个可执行文件(我想这对专业人士来说并不算什么)。

So here is my code: 所以这是我的代码:

first.c: 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;
}

second.h second.h

float go_to_the_other(float f);

second.c second.c

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

And the Makefile is (and yes, I used only tabs): 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

This is just an easy example, but it pretty much describes my problem. 这只是一个简单的例子,但是它几乎描述了我的问题。 I have all files in the same directory, and I use the command line: 我所有文件都在同一目录中,并且使用命令行:

mingw32-make first

But instead of compiling my files, I only get the message: 但是我没有编译文件,而是得到以下消息:

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

I guess it's probably something really stupid, but I just can't figure out what I'm doing wrong. 我想这可能真是愚蠢,但我无法弄清楚自己在做什么错。 I really appreciate any help on this. 我对此表示感谢。 Thank you so much in advance. 提前非常感谢您。

So I went and tried it and... it works for me with MinGW-4.7.1 on a Win7 machine.... I'm wondering if make it picking up an environment variable or some such. 所以我去尝试了一下,...它在Win7机器上的MinGW-4.7.1上对我有用。...我想知道是否让它选择了一个环境变量或类似的变量。

Try verifiying the version of make and gcc are what you expect 尝试验证make和gcc的版本是否符合您的期望

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

Also Try this makefile and see what happens. 还要尝试此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

Note convert spaces to tabs! 注意将空格转换为制表符!

And compile via 并通过编译

mingw32-make SHELL=cmd.exe first mingw32-make SHELL = cmd.exe首先

See what happens. 走着瞧吧。

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

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