• make编译相关教程(经验版)


    一、参考资料

    cmake详细教程(经验版)

    二、make常用指令

    # 多线程make编译
    make -j${nproc}
    
    # 打开日志,查看make构建的详细过程
    make VERBOSE=1 
    
    # 查看make版本
    make -v
    
    # 安装前的检查,包括权限检查
    make check
    
    # 将程序安装到系统中
    make install
    
    # 清理
    make clean
    
    # 打包前的检查
    make distcheck
    
    # 将程序和相关的档案,包装成一个压缩文件以供发布
    # 打包成 PACKAGE-VERSION.tar.gz 压缩包
    make dist
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    三、gdb工具常用操作

    1. 安装g++

    参考博客:gcc/g++版本多版本切换共存

    2. 编译时启用gdb工具

    使用 -g 启用gdb工具。

    g++ demo.cpp -g -o demo
    
    • 1

    参数解释

    • -g:指定启动dgb工具;
    • -o:指定编译输出的文件。

    3. ldd查看依赖库

    如果修改了 LD_LIBRARY_PATH ,使得依赖库发生改变,导致编译后的文件无法运行。可以通过 ldd 指令查看。

    ldd demo
    
    • 1
    yoyo@yoyo:~/PATH/TO$ ldd demo
            linux-vdso.so.1 =>  (0x00007fffe5bf9000)
            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6d9f8df000)
            /lib64/ld-linux-x86-64.so.2 (0x00007f6d9fca9000)
    
    • 1
    • 2
    • 3
    • 4

    4. 进入 gdb 调试模式

    gdb demo
    
    • 1
    yoyo@yoyo:~/PATH/TO$ gdb demo 
    GNU gdb (Ubuntu 8.2-0ubuntu1~16.04.1) 8.2
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from demo...done.
    (gdb)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    5. gdb常用指令

    指令含义样例
    b num在num行插入断点b 3
    b func在函数func的入口插入断点b main
    r运行程序(run)
    n下一步(next)
    c继续到下一个断点(continue)
    p a打印a的值(print(a))p a
    q退出调试

    6. 测试用例

    /*demo.cpp*/
    #include 
    int main()
    {
    	printf("hello C++ in Linux!\n");
    	printf("hello C-- in Linux!\n");
    	printf("hello C// in Linux!\n");
    	printf("hello Cxx in Linux!\n");
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    yoyo@yoyo:~/PATH/TO$ gdb demo 
    GNU gdb (Ubuntu 8.2-0ubuntu1~16.04.1) 8.2
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from demo...done.
    (gdb) b main
    Breakpoint 1 at 0x40050b: file demo.cpp, line 5.
    (gdb) r
    Starting program: /home/yoyo/PATH/TO/demo 
    
    Breakpoint 1, main () at demo.cpp:5
    5               printf("hello C++ in Linux!\n");
    (gdb) n
    hello C++ in Linux!
    6               printf("hello C-- in Linux!\n");
    (gdb) n
    hello C-- in Linux!
    7               printf("hello C// in Linux!\n");
    (gdb) n
    hello C// in Linux!
    8               printf("hello Cxx in Linux!\n");
    (gdb) n
    hello Cxx in Linux!
    9               return 0;
    (gdb) n
    10      }
    (gdb) n
    __libc_start_main (main=0x400507 <main()>, argc=1, argv=0x7fffffffd7b8, 
        init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
        stack_end=0x7fffffffd7a8) at ../csu/libc-start.c:325
    325     ../csu/libc-start.c: 没有那个文件或目录.
    (gdb)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
  • 相关阅读:
    [Linux]线程互斥
    LLM - 大语言模型 基于人类反馈的强化学习(RLHF)
    如何写好github上的README
    线性代数(三) | 向量组的秩 线性相关无关 几何直观理解 题解应用
    Kubernetes控制平面组件:Kubelet
    Apple App Store和Google Play 进行ASO有哪些区别?
    RISC-V入门(基础概念+汇编部分) 基于 汪辰老师的视频笔记
    8.论文学习Liver Tumor Segmentation and Classification: A Systematic Review
    堆栈介绍.
    QQd挂源码已更新最新加速项目程序全开源
  • 原文地址:https://blog.csdn.net/m0_37605642/article/details/132724865