详细报错信息:
/usr/include/c++/8/exception:101:3: error: ‘_GLIBCXX17_DEPRECATED‘ does not name a type; did you mean ‘_GLIBCXX_DEPRECATED‘? _GLIBCXX17_DEPRECATED ^~~~~~~~~~~~~~~~~~~~~ _GLIBCXX_DEPRECATED In file included from /usr/include/c++/8/bits/move.h:55:0, from /usr/include/c++/8/bits/nested_exception.h:40, from /usr/include/c++/8/exception:144, from /usr/include/c++/8/ios:39, from /usr/include/c++/8/ostream:38, from /usr/include/c++/8/iostream:39, from ../main.cpp:7: /usr/include/c++/8/type_traits:921:32: error: there are no arguments to ‘__is_constructible‘ that depend on a template parameter, so a declaration of ‘__is_constructible‘ must be available [-fpermissive]
经排查,报这个错的原因主要是eclipse include指定gcc目录和本机当前g++版本不匹配。
查看当前g++版本直接: gcc/g++ -v
查看Eclipse 指定include 目录: Window -> Preferences -> C/C++ -> Build -> Environment -> CPLUS_INCLUDE_PATH 项指定值
两种解决办法
首先查看当前系统装了那些g++,以debian/ubuntu为例:
ls /usr/bin/x86_64-linux-gnu-g++*
比如我装已装的g++:
/usr/bin/x86_64-linux-gnu-g++ /usr/bin/x86_64-linux-gnu-g++-7 /usr/bin/x86_64-linux-gnu-g++-4.8 /usr/bin/x86_64-linux-gnu-g++-8 /usr/bin/x86_64-linux-gnu-g++-5
1. 修改eclipse 指定include文件夹,和当前g++版本对应
查看当前g++版本,例如我当前的g++版本是7.4.0:
root@ming:~# g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=‘Debian 7.4.0-6‘ --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --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-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --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 --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 7.4.0 (Debian 7.4.0-6) root@ming:~#
打开: Window -> Preferences -> C/C++ -> Build -> Environment,选中CPLUS_INCLUDE_PATH项目,点击Edit,把值改成:/usr/include/c++/ (当前g++版本) /,例如我的就需要改成:/usr/include/c++/7/
2. 修改当前g++版本
例如eclipse 指定的g++ include 目录为: /usr/include/c++/8/,而我当前g++版本是 7.4.0
查看当前gcc软连接到哪,以debian(ubuntu)为例:
ls -l /usr/bin/g++ lrwxrwxrwx 1 root root 31 5月 29 08:42 /usr/bin/g++ -> /usr/bin/x86_64-linux-gnu-g++-7
x86_64-linux-gnu-g++-7 : 表示gcc 7
查看是否有g++-8,apt-get install g++-8
ls /usr/bin/x86_64-linux-gnu-g++-8
如果已安装g++8应该会有x86_64-linux-gnu-g++-8
删除当前g++软连接,重新连接g++到8:
rm /usr/bin/g++ ln -s /usr/bin/x86_64-linux-gnu-g++-8 /usr/bin/g++
尽量让gcc和g++版本保持一致,如果g++改为了8,那gcc尽量也改成8
查看是否有gcc-8, 如果没有debian(ubuntu): apt-get install gcc-8
ls /usr/bin/x86_64-linux-gnu-gcc-8
删除当前g++软连接,重新连接g++到8:
rm /usr/bin/gcc
ln -s /usr/bin/x86_64-linux-gnu-gcc-8 /usr/bin/gcc
到此可以重新编译一下了,祝一切顺利~