C++ 错误:GDB失败,消息:未采用可执行格式:无法识别文件格式

C++ 错误:GDB失败,消息:未采用可执行格式:无法识别文件格式,c++,gcc,visual-studio-code,compiler-errors,gdb,C++,Gcc,Visual Studio Code,Compiler Errors,Gdb,我正在尝试在VisualStudio代码中运行C++代码。但当您开始调试时,将显示以下错误: Unable to start debugging. Program path '/home/user/0/hlw2' is missing or invalid. GDB failed with message: "/home/user/0/hlw2": not in executable format: file format not recognized This may oc

我正在尝试在VisualStudio代码中运行C++代码。但当您开始调试时,将显示以下错误:

Unable to start debugging. Program path '/home/user/0/hlw2' is missing or invalid.
GDB failed with message: "/home/user/0/hlw2": not in executable format: file format not recognized
This may occur if the process's executable was changed after the process was started, such as when installing an update. Try re-launching the application or restarting the machine.
GDB版本:

gdb --v
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 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.
尝试通过GCC在终端中编译文件时:

gcc -g -o hlw2 hlw2.cpp
/usr/bin/ld: /tmp/cc40XHIQ.o: in function `main':
/home/user/0/hlw2.cpp:5: undefined reference to `std::cout'
/usr/bin/ld: /home/user/0/hlw2.cpp:5: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: /home/user/0/hlw2.cpp:5: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: /home/user/0/hlw2.cpp:5: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: /tmp/cc40XHIQ.o: in function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: /usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
gcc-g-o hlw2 hlw2.cpp
/usr/bin/ld:/tmp/cc40XHIQ.o:在函数“main”中:
/home/user/0/hlw2.cpp:5:对“std::cout”的未定义引用

/UR/BI/LD:/HOL/USE/HUL/HLW2.CPP:5:未定义的“STD::Basic IoSooS&STD::操作程序使用代码> G++<代码>代替C++代码> GCC < /Cuff>编译C++programs@Woodford,我无法在VSCode中选择g++。我可以选择“启动gdb”、“附加gdb”或“cpp构建和调试活动文件”。但在另一台安装了VSCode的计算机上,我能够选择g++(除了设置它什么都没有)。可能没有安装软件包?您将launch.json(调试)与tasks.json(构建任务)混为一谈。通常,您选择的gdb概要文件有一个用于调用构建任务的条目。然后需要确保正确配置生成任务。
gcc -g -o hlw2 hlw2.cpp
/usr/bin/ld: /tmp/cc40XHIQ.o: in function `main':
/home/user/0/hlw2.cpp:5: undefined reference to `std::cout'
/usr/bin/ld: /home/user/0/hlw2.cpp:5: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: /home/user/0/hlw2.cpp:5: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: /home/user/0/hlw2.cpp:5: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: /tmp/cc40XHIQ.o: in function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: /usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status