在Ubuntu中调试C++代码,你可以使用多种工具和方法。以下是一些常用的步骤和工具:
sudo apt install gcc g++
。Ctrl+Shift+P
并选择Configure default build task
,然后选择g++ build active file
。F5
并选择C++(GDB/LLDB)
,选择Default configuration
。hello.cpp
中编写代码。Ctrl+Shift+B
编译并构建工程。F5
调试工程。sudo apt install gdb
。-g
标志编译代码以包含调试信息,例如:g++ -g -O0 your_file.cpp -o your_executable
。gdb your_executable
启动GDB。break
、run
、next
、print
等)进行调试。.vscode
目录:.vscode
文件夹,并添加launch.json
和tasks.json
文件。launch.json
:tasks.json
:g++ -g -O0 ${file} -std=c++11 -D_GLIBCXX_DEBUG -o ${fileBasenameNoExtension}
。通过上述步骤和技巧,你可以在Ubuntu中有效地调试C++代码。选择适合你的工具和方法,可以提高调试效率和程序质量。