I am new to VSCode and I have encountered a problem which I haven't found the solution for days. When I was testing a very simple program below like this:
#include<iostream>
using namespace std;
int main()
{
int c;
cin>>c;
cout<<c;
return 0;
}
Following lines appeared in the terminal saying:
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\$$$$\AppData\Local\Temp\ccNwVdXS.o: in function `main':
D:/$PATH/hello.cpp:6: undefined reference to `std::istream::operator>>(int&)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/$PATH/hello.cpp:8: undefined reference to `std::ostream::operator<<(int)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\$$$$\AppData\Local\Temp\ccNwVdXS.o:hello.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\$$$$\AppData\Local\Temp\ccNwVdXS.o:hello.cpp:(.rdata$.refptr._ZSt3cin[.refptr._ZSt3cin]+0x0): undefined reference to `std::cin'
collect2.exe: error: ld returned 1 exit status
then the familiar '"prelaunch task exited with gcc" exited with 1' popped out again.(the same as g++) I have been configuring with the help of dozens of online blogs and this is the only problem unsolved right now. I serached though numerous sites and edited my configuration files on and on, and it just didn't work, the exactly same problem is still there. Any other program uninvolved with cin and cout is now working prefectly. The following extensions are in my vscode: C/C++ 1.19.9 C/C++ Extension Pack v1.3.0 (program above doesn't work whether disabled or not)
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb print",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Intel styled disassembly",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "C/C++: gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "c:\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "c:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb print",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Intel styled disassembly",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
tasks.json as followed:
{
"tasks": [
{
"type": "shell",
//"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "c:\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler generated tasks"
},
{
"type": "shell",
//"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "c:\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "c:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler generated tasks"
}
],
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
/*"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"showReuseMessage": true,
"clear": false
}*/
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": false,
"clear": false
},
}
What shall I do now?