您的位置:首页 > 博客中心 > 数据库 >

Makefile 加入gdb以及不同目录编译

时间:2022-03-13 22:36

条件:根目录下两个文件夹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

#endif

main.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中调试,希望能帮到大家。

Makefile 加入gdb以及不同目录编译,布布扣,bubuko.com

热门排行

今日推荐

热门手游