[英]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.