基本依赖

[root@localhost ~]# yum install ncurses-devel
[root@localhost ~]# yum install texinfo
[root@localhost ~]# yum install readline-devel


源码编译安装

[root@localhost ~]# wget https://github.com/cgdb/cgdb/archive/v0.7.0.tar.gz
[root@localhost ~]# tar xf v0.7.0.tar.gz 
[root@localhost ~]# cd cgdb-0.7.0/
[root@localhost cgdb-0.7.0]# ./autogen.sh 
[root@localhost cgdb-0.7.0]# ./configure --prefix=${HOME}/cgdb
[root@localhost cgdb-0.7.0]# make && make install


测试一下,

[root@localhost ~]# cd ~
[root@localhost ~]# cat main.c 
#include 
long num=0;
void hanoi(int n,char A,char B,char C)//理解为:有n个盘子在A上,通过B,移到C
{
    if(n==1)
    {
        printf("第%ld步:\t%c -> %c\n",++num,A,C);
    }
    else
    {
        hanoi(n-1,A,C,B);
        printf("第%ld步:\t%c -> %c\n",++num,A,C);
        hanoi(n-1,B,A,C);
    }
}

int main()
{
    int n=10;//10个盘子
    printf("盘子的移动方向如下\n");
    hanoi(n,'A','B','C');
    return 0;
}


效果图

[root@localhost ~]# gcc -g main.c 
[root@localhost ~]# ${HOME}/cgdb/bin/cgdb  a.out
进入GDB
(gdb) break main 
(gdb) run


CentOS7 安装cgdb_第1张图片




CentOS7 安装cgdb_第2张图片



安装完毕!