问题描述
代码(如果需要)>>>
// two pointer
#include <iostream>
#include <string>
using namespace std;
int main () {
int arr[] = {3,5,7,9,13,15,16} ;
int sum = 40 ;
int i =0;
int j = *(&arr + 1) - arr - 1 ;
bool found = false ;
cout<<j<<endl;
while ( i<j && found == false) {
if (arr[i] + arr[j] == sum){
found = true ;
}
else {
if ( arr[i] + arr[j] < sum){
i++ ;
}
else {
j-- ;
}
}
} // end of while
if (found == true)
cout<<arr[i]<<" "<<arr[j]<<endl;
return 0 ;
}
问题简要-我无法使用cmd终端使用VS Code中的一些调试标志来编译我的一小段代码,调试标志为:-D_GLIBCXX_DEBUG -fsanitize = undefined -ftrapv
详细信息- 我的机器-Windows 10 64位 编译器-来自mingw-w64的GCC C ++编译器(g ++)和GDB调试器 IDE-VS代码 文件名-main.cpp
因此,基本上,我是VS CODE或任何IDE环境的新手。我按照此处https://code.visualstudio.com/docs/cpp/config-mingw的步骤进行操作,以设置用于构建任务的VSCode,调试main.cpp .VS代码配置,task.json文件和launch.json文件。
使用这些命令通过VS Code中的cmd终端编译并运行main.cpp
C:\Users\Humble Fool\Desktop\dummy>g++ main.cpp
C:\Users\Humble Fool\Desktop\dummy>.\a.exe
(我的代码正确执行,如下所示) enter image description here
但是当我继续使用这些调试标志进行编译时,请通过终端中的以下命令来-D_GLIBCXX_DEBUG
-fsanitize=undefined
-ftrapv
:
C:\Users\Humble Fool\Desktop\dummy>g++ main.cpp -g -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
我收到此错误消息:
C:\Users\Humble Fool\Desktop\dummy>g++ main.cpp -g -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lubsan
collect2.exe: error: ld returned 1 exit status
因此,有人可以指导我逐步介绍如何使用那些调试标志进行编译吗? 如果可以使用task.json或launch.json文件进行修复,那么我是否必须为我在VS Code中导入的每个文件夹更新这两个文件?
我还将附加我的task.json和launch.json文件
tasks.json文件-
{
"version": "2.0.0","tasks": [
{
"type": "shell","label": "C/C++: g++.exe build active file","command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe","args": [
"-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"
],"options": {
"cwd": "${workspaceFolder}"
},"problemmatcher": [
"$gcc"
],"group": {
"kind": "build","isDefault": true
}
}
]
}
launch.json文件-
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more @R_399_4045@ion,visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0","configurations": [
{
"name": "g++.exe - Build and debug active file","type": "cppdbg","request": "launch","program": "${fileDirname}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe","setupCommands": [
{
"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true
}
],"prelaunchTask": "C/C++: g++.exe build active file"
}
]
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)