GCC7 ARMv7-标准头文件中的编译错误

时间:2017-10-23 07:52:30

标签: c++ ubuntu gcc arm c++17

我正在尝试使用GCC7为ARMv7-a架构编译我的C ++ 1z应用程序。我测试并使应用程序在Ubuntu 16.04(x86_64)中运行,但是当我尝试在ARM设备(Ubuntu 14.04)上编译它时,我最终在标准头文件中出现编译错误。错误的一个例子是:

In file included from /usr/include/c++/7/bits/ios_base.h:46:0,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /home/ubuntu/work/git_rep/surrogate/external/opencv/modules/core/include/opencv2/core/cvstd.inl.hpp:47,
                 from /home/ubuntu/work/git_rep/surrogate/external/opencv/modules/core/include/opencv2/core.hpp:3217,
                 from /home/ubuntu/work/git_rep/surrogate/external/opencv/modules/videoio/include/opencv2/videoio.hpp:46,
                 from /home/ubuntu/work/git_rep/surrogate/service/streaming/video/stereo_camera_stream.h:5,
                 from /home/ubuntu/work/git_rep/surrogate/service/streaming/video/stereo_camera_stream.cc:1:
/usr/include/c++/7/system_error: At global scope:
/usr/include/c++/7/system_error:151:31: error: ‘error_category’ does not name a type; did you mean ‘error_code’?
error_code(int __v, const error_category& __cat) noexcept
                          ^~~~~~~~~~~~~~
                          error_code
/usr/include/c++/7/system_error:160:27: error: ‘error_category’ does not name a type; did you mean ‘error_code’?
 assign(int __v, const error_category& __cat) noexcept
                       ^~~~~~~~~~~~~~
                       error_code
/usr/include/c++/7/system_error:180:11: error: ‘error_category’ does not name a type; did you mean ‘error_code’?
 const error_category&
       ^~~~~~~~~~~~~~
       error_code
/usr/include/c++/7/system_error:199:11: error: ‘error_category’ does not name a type; did you mean ‘error_code’?
 const error_category*  _M_cat;
       ^~~~~~~~~~~~~~
       error_code
/usr/include/c++/7/system_error: In constructor ‘std::error_code::error_code()’:
/usr/include/c++/7/system_error:149:20: error: class ‘std::error_code’ does not have any field named ‘_M_cat’
 : _M_value(0), _M_cat(&system_category()) { }
                ^~~~~~
/usr/include/c++/7/system_error:149:28: error: ‘system_category’ was not declared in this scope
 : _M_value(0), _M_cat(&system_category()) { }
                        ^~~~~~~~~~~~~~~
/usr/include/c++/7/system_error:149:28: note: suggested alternative:
/usr/include/c++/7/system_error:134:40: note:   ‘std::_V2::system_category’
_GLIBCXX_CONST const error_category& system_category() noexcept;
                                     ^~~~~~~~~~~~~~~

编译器建议将std::system_category替换为std::_V2::system_category,就好像标准头中会出现错误一样。我将头文件与我在为x86_64环境编译应用程序时使用的标头进行了比较,它们看起来是一样的,这让我猜测为什么针对ARMv7-a的编译失败了。

我正在使用CMake构建源代码,因此 - 据我所知 - 除了系统特定选项外,配置中不应存在其他差异。我比较了运行gcc -v时使用的两个编译器的配置。它们如下:

GCC7(x86_64)

Using built-in specs.
COLLECT_GCC=gcc
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='Ubuntu 7.2.0-1ubuntu1~16.04' --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 --with-sysroot=/ --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 --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.2.0 (Ubuntu 7.2.0-1ubuntu1~16.04) 

GCC7(ARMv7-a)

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/7/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.2.0-1ubuntu1~14.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=gcc4-compatible --disable-libstdcxx-dual-abi --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --disable-werror --enable-multilib --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 7.2.0 (Ubuntu/Linaro 7.2.0-1ubuntu1~14.04) 

对我而言,配置中的一个差异是--with-default-libstdcxx-abi,对于ARMv7-a设置为gcc4-compatible,对于x86_64设置为new,因为它会影响实现error_category班。

我不确定它是如何导致我看到的编译错误的,所以这是我转向你的地方。可能是什么原因以及我描述的编译错误的可能修复?

修改

将受影响文件中包含的头文件拆分为两个单独的头文件后 - 由此产生 - 编译单元,编译错误变为链接器错误,所有类似于以下内容:

../../lib/libservice.a(duplicate_camera_stream.cc.o):duplicate_camera_stream.cc:(.text+0x12c4): first defined here
../../lib/libservice.a(simulated_video_stream.cc.o): In function `std::make_error_code(std::io_errc)':
simulated_video_stream.cc:(.text+0x100d8): undefined reference to `std::iostream_category()'
../../lib/libservice.a(simulated_video_stream.cc.o): In function `std::make_error_condition(std::io_errc)':
simulated_video_stream.cc:(.text+0x10110): undefined reference to `std::iostream_category()'

这使我认为可能与我静态链接的OpenCV库的C ++标准不兼容。

解决方案

使用与我的其余代码相同的C ++标准编译OpenCV的源代码后,链接错误消失了,构建成功了。

通过将OpenCV标头包含在 - 并将旧C ++标准的库链接到 - 具有不同C ++标准的应用程序中,可能是这样吗?链接器和/或编译错误可能会发生?

0 个答案:

没有答案