无法识别的命令行选项‘-std=c++11’

unrecognized command line option ‘-std=c++11’

作为在 rasbian 上安装 ROS 的一部分(喘息)我不得不手动安装 console-bridge。我 运行 在

遇到了一个问题
cc1plus: error: unrecognized command line option ‘-std=c++11’

据我所知这是由于过时的 g++ 但当我尝试更新它时:

$ sudo apt-get install --only-upgrade g++
Reading package lists... Done
Building dependency tree       
Reading state information... Done
g++ is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.

我该怎么做才能解决这个问题?

$ apt-get source -b console-bridge
Reading package lists... Done
Building dependency tree       
Reading state information... Done
NOTICE: 'console-bridge' packaging is maintained in the 'Git' version control system at:
git://anonscm.debian.org/debian-science/packages/console-bridge.git
Skipping already downloaded file 'console-bridge_0.3.2-1.dsc'
Skipping already downloaded file 'console-bridge_0.3.2.orig.tar.gz'
Skipping already downloaded file 'console-bridge_0.3.2-1.debian.tar.xz'
Need to get 0 B of source archives.
Skipping unpack of already unpacked source in console-bridge-0.3.2
dpkg-buildpackage: source package console-bridge
dpkg-buildpackage: source version 0.3.2-1
dpkg-buildpackage: source changed by Jose Luis Rivero <jrivero@osrfoundation.org>
dpkg-buildpackage: host architecture armhf
 dpkg-source --before-build console-bridge-0.3.2
 fakeroot debian/rules clean
dh  clean --parallel
   dh_testdir -O--parallel
   debian/rules override_dh_auto_clean
make[1]: Entering directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2'
rm -f console_bridge-config.cmake
rm -f console_bridge.pc
dh_auto_clean --
make[1]: Leaving directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2'
   dh_clean -O--parallel
 debian/rules build
dh  build --parallel
   dh_testdir -O--parallel
   dh_auto_configure -O--parallel
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- console_bridge version 0.3.0
-- Performing Test HAS_VISIBILITY
-- Performing Test HAS_VISIBILITY - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf
   dh_auto_build -O--parallel
make[1]: Entering directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
/usr/bin/cmake -H/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2 -B/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf/CMakeFiles /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[2]: Entering directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
make -f CMakeFiles/console_bridge.dir/build.make CMakeFiles/console_bridge.dir/depend
make[3]: Entering directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
cd /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2 /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2 /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf/CMakeFiles/console_bridge.dir/DependInfo.cmake --color=
Scanning dependencies of target console_bridge
make[3]: Leaving directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
make -f CMakeFiles/console_bridge.dir/build.make CMakeFiles/console_bridge.dir/build
make[3]: Entering directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
/usr/bin/cmake -E cmake_progress_report /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf/CMakeFiles 2
[ 25%] Building CXX object CMakeFiles/console_bridge.dir/src/console.cpp.o
/usr/bin/c++   -Dconsole_bridge_EXPORTS -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2  -fvisibility=hidden -std=c++11 -Wall -Wextra -O3 -DNDEBUG -fPIC -I/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/include    -o CMakeFiles/console_bridge.dir/src/console.cpp.o -c /home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/src/console.cpp
cc1plus: error: unrecognized command line option ‘-std=c++11’
CMakeFiles/console_bridge.dir/build.make:57: recipe for target 'CMakeFiles/console_bridge.dir/src/console.cpp.o' failed
make[3]: *** [CMakeFiles/console_bridge.dir/src/console.cpp.o] Error 1
make[3]: Leaving directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
CMakeFiles/Makefile2:63: recipe for target 'CMakeFiles/console_bridge.dir/all' failed
make[2]: *** [CMakeFiles/console_bridge.dir/all] Error 2
make[2]: Leaving directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
Makefile:126: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/pi/ros_catkin_ws/external_src/console-bridge-0.3.2/obj-arm-linux-gnueabihf'
dh_auto_build: make -j1 returned exit code 2
debian/rules:7: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
Build command 'cd console-bridge-0.3.2 && dpkg-buildpackage -b -uc' failed.
E: Child process failed

解决方案

console-bridge-0.3.2/CMakeLists.txt 中,我发现了以下行:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")

我改成了:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra")

进行更改后我可以运行

$ apt-get source -b console-bridge

没有错误。

GCC 4.6 系列比较旧(2011-2012)。它首次发布时 C++11 仍称为 C++0x,因此它支持 -std=c++0x 开关而不是 std=c++11。它对 C++11 的支持相当不完整,因此大量使用 C++11 功能的现代代码可能会编译也可能不会编译。