[英]How to make 'make' work with mingw32 on Windows 7
我对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;
}
second.h
float go_to_the_other(float f);
second.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
我想这可能真是愚蠢,但我无法弄清楚自己在做什么错。 我对此表示感谢。 提前非常感谢您。
所以我去尝试了一下,...它在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首先
走着瞧吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.