训言主页

这段时间一直用的是Android Studio开发,用的java,忽然转用linux,c,Makefile还真有点不适应。

网上Makefile的教程真就只讲Makefile,如果c忘记了那么一点,可能就没那么好理解了。

以下是小白操作,纯小白。

本文参考:

跟我一起写Makefile https://seisman.github.io/how-to-write-makefile/introduction.html

Makefile的工作流程 http://c.biancheng.net/view/7091.html

写你的第一个makefile https://www.jianshu.com/p/c12a15d70bc3

gcc -v 查看linux,发现是有gcc。

vi技巧:

vi xxx      //创建xxx文件

esc 后:wq      //保存退出

cat xxx        //查看xxx文件

用vi编写三个文件hellomake.c、hellofunc.c、hellomake.h

#include <hellomake.h>
int main() {
  // call a function in another file
  myPrintHelloMake();
  return(0);
}
-----------------------------------
#include <stdio.h>
#include <hellomake.h>
void myPrintHelloMake(void) {
  printf("Hello makefiles!\n");
  return;
}
---------------------------------
/*
example include file
*/
void myPrintHelloMake(void);

同目录下用vi编写Makefile(两种方式,具体看参考链接)

hellmake: hellomake.c hellofunc.c
        gcc -o hellomake hellomake.c hellofunc.c -I.
--------------------------------------------------------
pre = hellomake.c hellofunc.c
hellmake: $(pre)
        gcc -o hellomake $(pre) -I.

执行 ./  编译成功

 

 

posted on 2021-01-29 15:26  訓言  阅读(134)  评论(0)    收藏  举报