条件:根目录下两个文件夹fun,head
./fun/function.h ./fun/function.c
./head/define.h
./main.c
以下为对应的文件源码,相对比较简单,仅仅起一个抛砖引玉的作用,到时候只需要照搬就行。
function.h
#include <stdio.h>
#include <stdlib.h>
#include "../head/define.h"
void show_hello();function.c
#include "function.h"
void show_hello()
{
printf("hello world,maxline = %d\n",MAXLINE);
}define.h
#ifndef _DEFINE_H_
#define _DEFINE_H_
#define MAXLINE 1024
#endifmain.c
#include "./fun/function.h"
int main()
{
show_hello();
return 0;
}Makefile
Source = $(wildcard fun/*.c) $(wildcard head/*.c)
Source += $(wildcard *.c)
Objs = $(Source:%.c=%.o)
CFLAGS += -I./fun -I./head
CFLAGS += -Wall -g
Target = test
all:$(Target)
$(Target):$(Objs)
$(CC) -o $(Target) $(Objs)
.PHONY:clean
clean:
-$(RM) $(Target) $(Objs)通过以上的makefile可以直接在gdb中调试,希望能帮到大家。
本文介绍了一个简单的C语言程序示例,包括头文件、函数定义及Makefile配置。通过该示例,读者可以了解如何组织C语言项目的文件结构,并使用Makefile进行编译和调试。
1289

被折叠的 条评论
为什么被折叠?



