【发布时间】:2017-11-18 20:22:39
【问题描述】:
如果我在 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
【问题讨论】:
-
发布 gdb 输出。
-
我的错,我编辑了代码以使其编译。 gdb 输出很简单:
-
发布完整的 gdb 输出,包括您尝试打印流变量的方式。