# 多线程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
参考博客:gcc/g++版本多版本切换共存
使用 -g 启用gdb工具。
g++ demo.cpp -g -o demo
参数解释
-g:指定启动dgb工具;-o:指定编译输出的文件。ldd查看依赖库如果修改了 LD_LIBRARY_PATH ,使得依赖库发生改变,导致编译后的文件无法运行。可以通过 ldd 指令查看。
ldd demo
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)
gdb demo
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 num | 在num行插入断点 | b 3 |
| b func | 在函数func的入口插入断点 | b main |
| r | 运行程序(run) | |
| n | 下一步(next) | |
| c | 继续到下一个断点(continue) | |
| p a | 打印a的值(print(a)) | p a |
| q | 退出调试 |
/*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;
}
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)