头文件和makefile的总结

本文详细介绍了Makefile文件的用途及其内容组成,包括编译和连接规则,为程序员提供自动化编译功能。同时,阐述了头文件的作用,如避免代码重复编写、程序规范化和清晰化,并提供了具体的头文件示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Makefiel文件:包括工程的编译,连接规则,为程序员提供了自动化的编译功能

//vi makefile

 

CC=gcc

CFLAGS=-g -Wall

LDFLAGG=

src=$(wildcard *.c)

target=$(basename $(src))

all:$(target)

 

.PHONY:clean all

clean:

               rm  -rf  *.o $(tsrget)

 

头文件:把运行程序是需要的头问价总结在一起,可以避免代码的重复写,直接调用 “head.h”,封装起来,使程序更规范化,清晰化

头文件  //vi head.h

#ifndef _HEAD_H_
#define _HEAD_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <malloc.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <dirent.h>
#include <assert.h>
#include <sys/wait.h>


#define HEAD_DEBUG


#define  error   do\
          {\
            fprintf(stderr,"[%s]:[%d]:%s\n",__func__,__LINE__,strerror(errno));\
            return -1;\
          }while(0)


#ifdef HEAD_DEBUG
#define debug(f,a...)   do\
             {\
               printf("[%s]:[%d] ",__func__,__LINE__);\
               printf(f,##a);\
             }while(0)
#else
#define debug(f,a...)
#endif        


#define DIR_TRUE  1
#define DIR_FALSE 0


#endif

 

上述两个文件,一个makefile 和 head.h 可以在每次写程序的时候,直接调用。方便化!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值