Makefile 实例实践
本文为原创文章,转帖需指明该文链接
目录结构如下:
comm/inc/apue.h
comm/errorhandler.c
atexit.c
Makefile
文件内容如下:
apue.h
#ifndef __apue_h__
2 #define __apue_h__ #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h> //for definition of erron
#include <stdarg.h> //ISO C variable arguments
#define MAXLINE 4096 //max line length
void err_dump(const char *fmt, ...);
1 void err_msg(const char *fmt, ...); #endif
errorhandler.c
#include "apue.h" #define ERR_MESSAGE_NEED 1
#define ERR_MESSAGE_NO 0 static void err_doit(int errnoflag, int error, const char *fmt, va_list ap); //print a message, dupm core, and terminate
void err_dump(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(ERR_MESSAGE_NEED, errno, fmt, ap);
va_end(ap);
abort();
exit();
}
atexit.c
#include "apue.h" static void my_exit1(void);
static void my_exit2(void); int main(void)
{
if( != atexit(my_exit2))
err_sys("can't register my_exit2");
if( != atexit(my_exit1))
err_sys("can't register my_exit1");
if( != atexit(my_exit1))
err_sys("can't register my_exit1");
printf("main is done\n");
return ;
}
Makefile
CC = gcc
CFLAGS = -Wall -O -g
CXXFLAGS =
INCLUDE = -I ./comm/inc
TARGET = atexit
#search paths for errorhandler.c,当存在多个路径时,可以使用 空格 或 : 来分割这些路径
vpath %.c ./comm
8 #下行是为依赖项 apue.h 准备的,比如 [errorhandler.o:errorhandler.c apue.h] 里的
vpath %.h ./comm/inc OBJS = errorhandler.o atexit.o
all:$(OBJS)
$(CC) $(CFLAGS) $(INCLUDE) -o $(TARGET) $^
@echo ---target:$@
@echo ---depend:$^
16 #下行的 apue.h,可以不必写出来
errorhandler.o:errorhandler.c apue.h
$(CC) $(CFLAGS) $(INCLUDE) -c $^
@echo ---target:$@
@echo ---depend:$^
atexit.o:atexit.c apue.h
$(CC) $(CFLAGS) $(INCLUDE) -c $^
@echo ---target:$@
@echo ---depend:$^
clean:
rm -f *.o
rm -f $(TARGET)
在 Makefile 里
INCLUDE = -I ./comm/inc 是为 gcc 编译文件时使用的
vpath %.c ./comm vpath %.h ./comm.inc 是为 make 程序使用
@echo ---target:$@ 是为了测试 $@ 是什么内容 @echo ---depend:$^ 是为了测试 $^ 是什么内容
Makefile 的自动变量
$@ 表示目标文件
$^ 表示所有的依赖文件
$< 表示第一个依赖文件
$? 表示比目标还要新的依赖文件列表
Makefile 实例实践的更多相关文章
- makefile实例(1)-helloworld
简单makefile实例 1,源文件: main.cpp #include <stdio.h> int main() { printf("Hello World\n") ...
- Ubuntu下比较通用的makefile实例
本文转自http://blog.chinaunix.net/uid-20608849-id-360294.html 笔者在写程序的时候会遇到这样的烦恼:一个项目中可能会有很多个应用程序,而新建一个应 ...
- Linux下GCC和Makefile实例(从GCC的编译到Makefile的引入)
一.确认已经装好了GCC和Make的软件包 可以使用whereis命令查看: 如果whereis gcc和whereis make命令有结果,说明安装了这两个软件,可以继续往下做. 二.使用GCC ...
- makefile实例(3)-多个文件实例优化
我们先看一下make是如何工作的在默认的方式下,也就是我们只输入make命令.那么,1.make会在当前目录下找名字叫“Makefile”或“makefile”的文件.2.如果找到,它会找文件中的第一 ...
- makefile实例(2)-多个文件实例
1,源文件依赖关系 defs.h command.h buffer.h main.cpp * util.cpp * kde.cpp * * command.cpp * * display.cpp * ...
- RxJava/RxAndroid 使用实例实践
原文地址 RxAndroid Tutorial响应式编程(Reactive programming)不是一种API,而是一种新的非常有用的范式,而RxJava就是一套基于此思想的框架,在Android ...
- Linux下GCC和Makefile实例(从GCC的编译到Makefile的引入) 转
http://www.crazyant.net/2011/10/29/linux%E4%B8%8Bgcc%E5%92%8Cmakefile%E5%AE%9E%E4%BE%8B%EF%BC%88%E4% ...
- makefile实例
#.PHONY:cleanall cleanobj cleandiff #cleanall:cleandiff cleanobj # rm program #cleanobj: # rm obj.c ...
- Makefile 实例
CROSS_COMPILE = HI_CFLAGS= -Wall -O2 -g -march=armv7-a -mcpu=cortex-a9 -mfloat-abi=softfp -mfpu=vfpv ...
随机推荐
- RTP/RTCP、TCP、UDP、RTMP、RTSP
OSI中的层 功能 TCP/IP协议族 应用层 文件传输,电子邮件,文件服务,虚拟终端 TFTP,FTP,HTTP,SNMP,SMTP,DNS,RIP,Telnet 表示层 数据格式化,代码转换,数据 ...
- unity 实时间接光照 解决方案
https://www.youtube.com/watch?v=D7LjsabD4V4 这个很强 他runtime bake lightprobe 之后走assetbundle加载 Place Pro ...
- Axure 简单原型设计
简介 Axure RP是一个专业的快速原型设计工具.Axure(发音:Ack-sure),代表美国Axure公司:RP则是Rapid Prototyping(快速原型)的缩写. Axure RP是美国 ...
- shell遍历文件夹并执行命令
背景: 有一个源码包里面包含很多子目录和makefile,打包后的压缩包太大,需要将make生成的所有二进制文件删除然后再打包. 需求: 因此,要求在制定目录的所有递归子目录中执行make clean ...
- 转: codereview工具之 review board 选型与实践
转:ReviewBoard代码评审实践总结 http://my.oschina.net/donhui/blog/350074 svn与review board 结合实践 http://my.oschi ...
- projecteuler---->problem=10----Summation of primes
title: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below tw ...
- Python爬虫碎碎念
最近领导给了一个任务,从单位的数据库里面导出所有的数据,存到本地excel表格.我就想,这不挺简单的么,给我数据库的密码账户,几条语句搞定. 结果让人大失所望,单位数据库只能通过后台管理系统查看,平台 ...
- Visual studio之C# 重新定义Messbox的显示窗口位置
背景 当前做的APP需要新建一个设置窗口,该设置窗口会出现在靠近屏幕边缘位置,但主窗口铺满屏幕,设置窗口会弹出一些讯息,但默认情况下Messagebox窗口会居中于主窗口,这不太符合要求,正常应该居中 ...
- hibernate 一对多关联
package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import javax.persistenc ...
- 彻底删除Oracle 11g的方法
1.关闭oracle所有的服务. 可以在windows的服务管理器中关闭. 2.打开注册表:regedit 打开路径:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlS ...