G++简单程序的编译错误
在尝试学习一些 C 之后,我尝试了一些 C++ 编程,以直观地了解语言之间的一些差异。当尝试编译程序时,我在库中遇到很多错误
代码:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
return 0;
}
和错误:
In file included from /usr/include/c++/9/cstdio:42,
from /usr/include/c++/9/ext/string_conversions.h:43,
from /usr/include/c++/9/bits/basic_string.h:6493,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from new.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/9/include/stdio.h:46:25: error: conflicting declaration ‘typedef struct __sFILE FILE’
46 | typedef struct __sFILE FILE;
| ^~~~
In file included from /usr/include/wchar.h:46,
from /usr/include/c++/9/cwchar:44,
from /usr/include/c++/9/bits/postypes.h:40,
from /usr/include/c++/9/iosfwd:40,
from /usr/include/c++/9/ios:38,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from new.cpp:1:
/usr/include/x86_64-linux-gnu/bits/types/FILE.h:7:25: note: previous declaration as ‘typedef struct _IO_FILE FILE’
7 | typedef struct _IO_FILE FILE;
| ^~~~
In file included from /usr/include/c++/9/ext/string_conversions.h:43,
from /usr/include/c++/9/bits/basic_string.h:6493,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from new.cpp:1:
/usr/include/c++/9/cstdio:99:11: error: ‘::fpos_t’ has not been declared
99 | using ::fpos_t;
| ^~~~~~
/usr/include/c++/9/cstdio:101:11: error: ‘::clearerr’ has not been declared
101 | using ::clearerr;
| ^~~~~~~~
/usr/include/c++/9/cstdio:102:11: error: ‘::fclose’ has not been declared
102 | using ::fclose;
| ^~~~~~
/usr/include/c++/9/cstdio:103:11: error: ‘::feof’ has not been declared
103 | using ::feof;
| ^~~~
/usr/include/c++/9/cstdio:104:11: error: ‘::ferror’ has not been declared
104 | using ::ferror;
| ^~~~~~
/usr/include/c++/9/cstdio:105:11: error: ‘::fflush’ has not been declared
105 | using ::fflush;
| ^~~~~~
/usr/include/c++/9/cstdio:107:11: error: ‘::fgetpos’ has not been declared
107 | using ::fgetpos;
| ^~~~~~~
/usr/include/c++/9/cstdio:109:11: error: ‘::fopen’ has not been declared
109 | using ::fopen;
| ^~~~~
/usr/include/c++/9/cstdio:110:11: error: ‘::fprintf’ has not been declared
110 | using ::fprintf;
| ^~~~~~~
/usr/include/c++/9/cstdio:114:11: error: ‘::freopen’ has not been declared
114 | using ::freopen;
| ^~~~~~~
/usr/include/c++/9/cstdio:115:11: error: ‘::fscanf’ has not been declared
115 | using ::fscanf;
| ^~~~~~
/usr/include/c++/9/cstdio:116:11: error: ‘::fseek’ has not been declared
116 | using ::fseek;
| ^~~~~
/usr/include/c++/9/cstdio:117:11: error: ‘::fsetpos’ has not been declared
117 | using ::fsetpos;
| ^~~~~~~
/usr/include/c++/9/cstdio:118:11: error: ‘::ftell’ has not been declared
118 | using ::ftell;
| ^~~~~
/usr/include/c++/9/cstdio:126:11: error: ‘::perror’ has not been declared
126 | using ::perror;
| ^~~~~~
/usr/include/c++/9/cstdio:131:11: error: ‘::remove’ has not been declared
131 | using ::remove;
| ^~~~~~
/usr/include/c++/9/cstdio:132:11: error: ‘::rename’ has not been declared
132 | using ::rename;
| ^~~~~~
/usr/include/c++/9/cstdio:133:11: error: ‘::rewind’ has not been declared
133 | using ::rewind;
| ^~~~~~
/usr/include/c++/9/cstdio:135:11: error: ‘::setbuf’ has not been declared
135 | using ::setbuf;
| ^~~~~~
/usr/include/c++/9/cstdio:136:11: error: ‘::setvbuf’ has not been declared
136 | using ::setvbuf;
| ^~~~~~~
/usr/include/c++/9/cstdio:139:11: error: ‘::tmpfile’ has not been declared
139 | using ::tmpfile;
| ^~~~~~~
/usr/include/c++/9/cstdio:141:11: error: ‘::tmpnam’ has not been declared
141 | using ::tmpnam;
| ^~~~~~
/usr/include/c++/9/cstdio:176:11: error: ‘::vfscanf’ has not been declared
176 | using ::vfscanf;
| ^~~~~~~
/usr/include/c++/9/cstdio:177:11: error: ‘::vscanf’ has not been declared
177 | using ::vscanf;
| ^~~~~~
/usr/include/c++/9/cstdio:179:11: error: ‘::vsscanf’ has not been declared
179 | using ::vsscanf;
| ^~~~~~~
/usr/include/c++/9/cstdio:186:22: error: ‘__gnu_cxx::vfscanf’ has not been declared
186 | using ::__gnu_cxx::vfscanf;
| ^~~~~~~
/usr/include/c++/9/cstdio:187:22: error: ‘__gnu_cxx::vscanf’ has not been declared
187 | using ::__gnu_cxx::vscanf;
| ^~~~~~
/usr/include/c++/9/cstdio:189:22: error: ‘__gnu_cxx::vsscanf’ has not been declared
189 | using ::__gnu_cxx::vsscanf;
| ^~~~~~~
g++ -v 命令结果:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
注意:
我尝试重新安装 g++,因为我认为某些库已损坏,但它不起作用。 另外,我使用 Ubuntu 20.04 LTS,如果这有用的话
I tried some C++ programming after trying to learn some C, to see some differences between languages first hand. When trying to compile the program, I get a lot of errors in libraries
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
return 0;
}
and errors:
In file included from /usr/include/c++/9/cstdio:42,
from /usr/include/c++/9/ext/string_conversions.h:43,
from /usr/include/c++/9/bits/basic_string.h:6493,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from new.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/9/include/stdio.h:46:25: error: conflicting declaration ‘typedef struct __sFILE FILE’
46 | typedef struct __sFILE FILE;
| ^~~~
In file included from /usr/include/wchar.h:46,
from /usr/include/c++/9/cwchar:44,
from /usr/include/c++/9/bits/postypes.h:40,
from /usr/include/c++/9/iosfwd:40,
from /usr/include/c++/9/ios:38,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from new.cpp:1:
/usr/include/x86_64-linux-gnu/bits/types/FILE.h:7:25: note: previous declaration as ‘typedef struct _IO_FILE FILE’
7 | typedef struct _IO_FILE FILE;
| ^~~~
In file included from /usr/include/c++/9/ext/string_conversions.h:43,
from /usr/include/c++/9/bits/basic_string.h:6493,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from new.cpp:1:
/usr/include/c++/9/cstdio:99:11: error: ‘::fpos_t’ has not been declared
99 | using ::fpos_t;
| ^~~~~~
/usr/include/c++/9/cstdio:101:11: error: ‘::clearerr’ has not been declared
101 | using ::clearerr;
| ^~~~~~~~
/usr/include/c++/9/cstdio:102:11: error: ‘::fclose’ has not been declared
102 | using ::fclose;
| ^~~~~~
/usr/include/c++/9/cstdio:103:11: error: ‘::feof’ has not been declared
103 | using ::feof;
| ^~~~
/usr/include/c++/9/cstdio:104:11: error: ‘::ferror’ has not been declared
104 | using ::ferror;
| ^~~~~~
/usr/include/c++/9/cstdio:105:11: error: ‘::fflush’ has not been declared
105 | using ::fflush;
| ^~~~~~
/usr/include/c++/9/cstdio:107:11: error: ‘::fgetpos’ has not been declared
107 | using ::fgetpos;
| ^~~~~~~
/usr/include/c++/9/cstdio:109:11: error: ‘::fopen’ has not been declared
109 | using ::fopen;
| ^~~~~
/usr/include/c++/9/cstdio:110:11: error: ‘::fprintf’ has not been declared
110 | using ::fprintf;
| ^~~~~~~
/usr/include/c++/9/cstdio:114:11: error: ‘::freopen’ has not been declared
114 | using ::freopen;
| ^~~~~~~
/usr/include/c++/9/cstdio:115:11: error: ‘::fscanf’ has not been declared
115 | using ::fscanf;
| ^~~~~~
/usr/include/c++/9/cstdio:116:11: error: ‘::fseek’ has not been declared
116 | using ::fseek;
| ^~~~~
/usr/include/c++/9/cstdio:117:11: error: ‘::fsetpos’ has not been declared
117 | using ::fsetpos;
| ^~~~~~~
/usr/include/c++/9/cstdio:118:11: error: ‘::ftell’ has not been declared
118 | using ::ftell;
| ^~~~~
/usr/include/c++/9/cstdio:126:11: error: ‘::perror’ has not been declared
126 | using ::perror;
| ^~~~~~
/usr/include/c++/9/cstdio:131:11: error: ‘::remove’ has not been declared
131 | using ::remove;
| ^~~~~~
/usr/include/c++/9/cstdio:132:11: error: ‘::rename’ has not been declared
132 | using ::rename;
| ^~~~~~
/usr/include/c++/9/cstdio:133:11: error: ‘::rewind’ has not been declared
133 | using ::rewind;
| ^~~~~~
/usr/include/c++/9/cstdio:135:11: error: ‘::setbuf’ has not been declared
135 | using ::setbuf;
| ^~~~~~
/usr/include/c++/9/cstdio:136:11: error: ‘::setvbuf’ has not been declared
136 | using ::setvbuf;
| ^~~~~~~
/usr/include/c++/9/cstdio:139:11: error: ‘::tmpfile’ has not been declared
139 | using ::tmpfile;
| ^~~~~~~
/usr/include/c++/9/cstdio:141:11: error: ‘::tmpnam’ has not been declared
141 | using ::tmpnam;
| ^~~~~~
/usr/include/c++/9/cstdio:176:11: error: ‘::vfscanf’ has not been declared
176 | using ::vfscanf;
| ^~~~~~~
/usr/include/c++/9/cstdio:177:11: error: ‘::vscanf’ has not been declared
177 | using ::vscanf;
| ^~~~~~
/usr/include/c++/9/cstdio:179:11: error: ‘::vsscanf’ has not been declared
179 | using ::vsscanf;
| ^~~~~~~
/usr/include/c++/9/cstdio:186:22: error: ‘__gnu_cxx::vfscanf’ has not been declared
186 | using ::__gnu_cxx::vfscanf;
| ^~~~~~~
/usr/include/c++/9/cstdio:187:22: error: ‘__gnu_cxx::vscanf’ has not been declared
187 | using ::__gnu_cxx::vscanf;
| ^~~~~~
/usr/include/c++/9/cstdio:189:22: error: ‘__gnu_cxx::vsscanf’ has not been declared
189 | using ::__gnu_cxx::vsscanf;
| ^~~~~~~
g++ -v command results:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
Note:
I tried reinstalling g++, because I thought some libraries were corrupted, but it didn't work.
Also, I use Ubuntu 20.04 LTS, if that's useful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
系统标头
/usr/lib/gcc/x86_64-linux-gnu/9/include/stdio.h
中有重复的符号。但根据 Ubuntu manifest,您的 GCC 版本确实<强>不包含此文件,也许它已经从不同的版本中过时了?我的建议是删除这个文件,或者删除(或者移走,以防万一)整个文件夹(那里可能还有其他过时的文件)并重新安装 libgcc-9-dev 包。
如果您想在删除文件之前确定,可以使用以下命令检查它是否属于任何包:
You have a duplicate symbol in a system header
/usr/lib/gcc/x86_64-linux-gnu/9/include/stdio.h
. But according to the Ubuntu manifest, your GCC version does not include this file, maybe it has been left stale from a different version?My adivice is to delete this file, or maybe delete (or move away, just in case) the whole folder (there may be other stale files there) and reinstall the
libgcc-9-dev
package alltogether.If you want to be sure before deleting the file you can check whether it belongs to any package with the command: