错误:GDB 失败并显示消息:不是可执行格式:无法识别文件格式

问题描述 投票:0回答:1

我正在尝试在 Visual Studio Code 中运行 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 version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

尝试通过 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
c++ gcc visual-studio-code compiler-errors gdb
1个回答
0
投票

对不起,兄弟,我遇到了同样的问题,但没有解决方案:(

© www.soinside.com 2019 - 2024. All rights reserved.