Reputation: 1
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
Upvotes: 0
Views: 1091
Reputation: 98348
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:
$ dpkg -S /usr/lib/gcc/x86_64-linux-gnu/9/include/stdio.h
Upvotes: 1