如果我在gdb调试器中运行以下代码并输入print inFile,我会收到消息“不完整类型”。
#include <fstream>
#include <iostream>
int main() {
std::ifstream inFile;
inFile.open("testFile.txt");
std::cout<<"In the debugger if I print the inFile variable at this point I get the incomplete type message";
inFile.close();
}
这使得调试变得相当困难。任何人都知道这可能是什么原因?
这是我编译文件的方式:
g++ -g -std=c++11 main.cpp -o main
这是完整的GDB输出:
>> gdb main
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main...done.
(gdb) break main
Breakpoint 1 at 0x400ac2: file main.cpp, line 3.
(gdb) run
Starting program: ~/main
Breakpoint 1, main () at main.cpp:3
3 int main() {
(gdb) n
4 std::ifstream inFile;
(gdb)
5 inFile.open("testFile.txt");
(gdb) print inFile
$1 = <incomplete type>
(gdb)
我使用了帖子中描述的方法ks1322,并获得了以下消息
dpkg --list | grep libstdc++
ii libstdc++-5-dev:amd64 5.4.0-6ubuntu1~16.04.5 amd64 GNU Standard C++ Library v3 (development files)
ii libstdc++6:amd64 5.4.0-6ubuntu1~16.04.5 amd64 GNU Standard C++ Library v3
在
sudo apt-get install libstdc++
显示器
libstdc++6 libstdc++6-5-dbg-m68k-cross
libstdc++6-4.7-dbg libstdc++6-5-dbg-mips64-cross
libstdc++6-4.7-dbg-armel-cross libstdc++6-5-dbg-mips64el-cross
libstdc++6-4.7-dbg-armhf-cross libstdc++6-5-dbg-mips-cross
libstdc++6-4.7-dev libstdc++6-5-dbg-mipsel-cross
libstdc++6-4.7-dev-armel-cross libstdc++6-5-dbg-powerpc-cross
libstdc++6-4.7-dev-armhf-cross libstdc++6-5-dbg-powerpcspe-cross
libstdc++6-4.7-doc libstdc++6-5-dbg-ppc64-cross
libstdc++6-4.7-pic libstdc++6-5-dbg-ppc64el-cross
libstdc++6-4.7-pic-armel-cross libstdc++6-5-dbg-s390x-cross
libstdc++6-4.7-pic-armhf-cross libstdc++6-5-dbg-sh4-cross
libstdc++6-4.8-dbg libstdc++6-5-dbg-sparc64-cross
libstdc++6-4.8-dbg-arm64-cross libstdc++6-alpha-cross
libstdc++6-4.8-dbg-armhf-cross libstdc++6-arm64-cross
libstdc++6-4.8-dbg-powerpc-cross libstdc++6-armel-cross
libstdc++6-4.8-dbg-ppc64el-cross libstdc++6-armhf-cross
libstdc++6-4.9-dbg libstdc++6-hppa-cross
libstdc++6-4.9-dbg-arm64-cross libstdc++6-m68k-cross
libstdc++6-4.9-dbg-armel-cross libstdc++6-mips64-cross
libstdc++6-4.9-dbg-armhf-cross libstdc++6-mips64el-cross
libstdc++6-4.9-dbg-powerpc-cross libstdc++6-mips-cross
libstdc++6-4.9-dbg-ppc64el-cross libstdc++6-mipsel-cross
libstdc++6-4.9-dbg-s390x-cross libstdc++6-powerpc-cross
libstdc++6-5-dbg libstdc++6-powerpcspe-cross
libstdc++6-5-dbg-alpha-cross libstdc++6-ppc64-cross
libstdc++6-5-dbg-arm64-cross libstdc++6-ppc64el-cross
libstdc++6-5-dbg-armel-cross libstdc++6-s390x-cross
libstdc++6-5-dbg-armhf-cross libstdc++6-sh4-cross
libstdc++6-5-dbg-hppa-cross libstdc++6-sparc64-cross
答案 0 :(得分:4)
您需要为libstdc ++安装调试符号(这是1 2 3 4 5 6
所在的位置)。有关std::ifstream
的信息,请参见here the similar issue:
由gdb引起的,没有标准的调试信息 图书馆。用-g编译你的程序是不够的,因为它是 标准库中用于定义这些类型的代码。对于 例如,如果你在基于Debian的系统中使用gcc,那么就是a 您可以安装的-dbg版本的libstdc ++。例如:
因此,您需要使用std::stringstream
安装此程序包libstdc++<your version>-dbg
:
apt-get
将sudo apt-get install libstdc++<your version>-dbg
替换为您的libstdc ++版本。
答案 1 :(得分:0)
一个有用的解决方案可以在这里找到: https://stackoverflow.com/a/58754863/11867786