Makefile使用及多文件gdb 调试

文件内容

[kou@localhost makefile]$ cat 1.c
#include "3.h"
int main()
{
    key_t key = ftok(".",1);
    printf("%d\n",add(1,2));
    return 0;
}

[kou@localhost makefile]$ cat 2.c
#include "3.h"
int add(int a, int b)
{
    return a + b;
}
[kou@localhost makefile]$ cat 3.h
#pragma once
#include<stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>

int add(int a,int b);

正常情况编译
这里写图片描述

Makefile文件

all:1.o 2.o
    gcc 1.o 2.o -o main
1.o:1.c
    gcc -c 1.c -o 1.o
2.o:2.c
    gcc -c 2.c -o 2.o
.PHONY:clean
clean:
    rm -rf *.o

这里写图片描述

makfile编写

gcc hello.c -o hello  -I/home/hello/include   -L/home/hello/lib    -lworld
  • -I /home/hello/include,表示将/home/hello/include目录作为第一个寻找头文件的目录,寻找的顺序是:/home/hello/include–>/usr/include–>/usr/local/include找不到的话查找默认目录
  • -L /home/hello/lib,表示将/home/hello/lib目录作为第一个寻找库文件的目录, 寻找的顺序是:/home/hello/lib–>/lib–>/usr/lib–>/usr/local/lib

  • -l word , 表示**寻找动态链接库文件**libword.so(也就是文件名去掉前缀和后缀所代表的库文件)

多文件gdb

每一个gcc 后面都要-g

all:1.o 2.o
    gcc -g -o all 1.o 2.o
1.o:1.c
    gcc -c 1.c -o 1.o -g
2.o:2.c
    gcc -c 2.c  -o 2.o -g
clean:
    rm -rf *o
    rm -rf output.c
    rm -f all
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值