linux 下makefile的使用举例
2012-12-05 16:53
288 查看
该程序在linux平台下用C语言实现
有两个头文件m1.h m2.h 对应的实现文件m1.c m2.c 调试文件test.c
案例代码如下:
m1.h
m2.h
m1.c
m2.c
test.c
Makefile文件两种写法:
1.
2.
注意: 1. 三个常用变量:$@(目标文件),$^(所有依赖文件),$<(第一个依赖文件)
2.命令行处需要Tab键空行
3.makefile文件中编译命令其实就是一个递归过程
4. 编译指令make 或 make -f Makefile
有两个头文件m1.h m2.h 对应的实现文件m1.c m2.c 调试文件test.c
案例代码如下:
m1.h
#include<stdio.h> void m1_print(char *str);
m2.h
#include<stdio.h> void m2_print(char *str);
m1.c
#include<stdio.h> #include"m1.h" void m1_print(char *str){ printf("this is string %s\n",str); }
m2.c
#include<stdio.h> #include"m2.h" void m2_print(char *str){ printf("this is string %s.",str); }
test.c
#include<stdio.h> #include"m1.h" #include"m2.h" void main(){ m1_print("Hello"); m2_print("World"); }
Makefile文件两种写法:
1.
main:test.o m1.o m2.o gcc -o testt test.o m1.o m2.o test.o:test.c m1.h m2.h gcc -c test.c m1.o:m1.c m1.h gcc -c m1.c m2.o:m2.c m2.h gcc -c m2.c
2.
ma:test.o m1.o m2.o gcc -o $@ $^ test.o:test.c m1.h m2.h gcc -c $< m1.o:m1.c m1.h gcc -c $< m2.o:m2.c m2.h gcc -c $<
注意: 1. 三个常用变量:$@(目标文件),$^(所有依赖文件),$<(第一个依赖文件)
2.命令行处需要Tab键空行
3.makefile文件中编译命令其实就是一个递归过程
4. 编译指令make 或 make -f Makefile
相关文章推荐
- linux下使用autotools创建makefile文件
- Linux中的静态库、共享库、头文件及makefile文件举例
- Linux makefile 教程 ,makefile 怎么使用 使用makefile 编译程序
- linux IP 命令使用举例
- windows下使用windump 和 awk,linux 下tcpdump举例
- Linux下gcc,g++,makefile的使用
- Linux中,pthread_cond_t, 条件变量的使用举例
- 在linux下如何使用Makefile对fortran程序进行编译
- 一个linux下g++使用的 makefile 模板
- linux IP 命令使用举例
- linux下练习 c++ 库函数排序使用举例
- linux makefile 只能使用Tab键进行文本缩进
- linux内 cp命令参数及使用举例
- linux 生成和使用动态链接库和静态链接库的Makefile编写
- [Linux-C++] Make 的使用和Makefile的编写
- 【Linux】Makefile 使用总结
- linux IP 命令使用举例
- 【ARM-Linux开发】Makefile 使用总结
- Linux Makefile ifeq正确使用
- [调用.so动态链接库]Linux Makefile介绍使用的环境深入浅出