简体   繁体   English

如何编写自己的 Makefile(.mak 文件)?

[英]How can I write my own Makefile (.mak file)?

I want to know how to write a Makefile ( .mak -file).我想知道如何编写Makefile ( .mak -file)。

I have 4 files:我有4个文件:

  1. myfunctions.h : myfunctions.h
//myfunctions.h
#ifndef MYFUNCTIONS_H
#define MYFUNCTIONS_H

void show();

#endif
  1. myfunctions.c : myfunctions.c :
//myfunctions.c
#include "myfunctions.h"

void show(){
printf("running!");
}
  1. mymain.c : mymain.c :
//mymain.c
#include "myfunctions.h"

int main(int argc, char *argv[]) {
show();
}
  1. mymake.mak : mymake.mak :
//mymake.mak
myprogramm: mymain.c myfunctions.c  
    gcc -o myprogramm mymain.c myfunctions.c -I.

I run the mymake.mak with make mymakemak.mak and I get this error:我运行mymake.makmake mymakemak.mak和我得到这个错误:

make: Nothing to be done for `mymake.mak'.

What am I doing wrong?我究竟做错了什么?

You need to use the file as the Makefile itself, not as the target.您需要将该文件用作 Makefile 本身,而不是用作目标。 So you should be running所以你应该跑

make -f mymake.mak

You can also rename mymake.mak to Makefile or makefile and re-run make .您还可以将mymake.mak重命名为Makefilemakefile并重新运行make

What make is trying to do here is create a target called mymake.mak . make在这里试图做的是创建一个名为mymake.mak的目标。 Since mymake.mak already exists, make thinks its job is done and it exits.由于mymake.mak已经存在, make认为它的工作已经完成并退出。

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

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