Crosstool-ng g ++没有编译c ++ 11 std :: current_exception

时间:2017-06-26 11:21:55

标签: c++11 exception-handling crosstool-ng

我使用Crosstool-ng构建了一个gcc工具链,但生成的g ++不会编译和/或链接C ++ 11异常。

如果我尝试编译:

#include <exception>

int main()
{
    std::current_exception();
}

通过:

arm-none-linux-gnueabihf-g++ -std=c++11 foo.cpp

我明白了:

foo.cpp: In function 'int main()':
foo.cpp:5:9: error: 'current_exception' is not a member of 'std'
         std::current_exception();
         ^~~

然而,如果我另外提供cortex-a9作为cpu,那么haviour会改变:

arm-none-linux-gnueabihf-g++ -mcpu=cortex-a9 -std=c++11 foo.cpp

结果:

/tmp/cc13AEjE.o: In function `main':
foo.cpp:(.text+0x14): undefined reference to `std::current_exception()'
foo.cpp:(.text+0x20): undefined reference to 
`std::__exception_ptr::exception_ptr::~exception_ptr()'
collect2: error: ld returned 1 exit status

我在工具链中为current_exception加油,这对我来说似乎很好:

grep -r -e current_exception arm-none-linux-gnueabihf/


Binary file arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/sysroot/lib/libstdc++.so.6.0.22 matches
Binary file arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/sysroot/lib/libstdc++.a matches
Binary file arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/sysroot/lib/libsupc++.a matches
arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/6.3.0/cxxabi.h:  __cxa_current_exception_type() _GLIBCXX_NOTHROW __attribute__ ((__pure__));
arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/6.3.0/future:     (*_M_result)->_M_error = current_exception();
arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/6.3.0/future:     (*_M_result)->_M_error = current_exception();
arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/6.3.0/bits/exception_ptr.h:  exception_ptr current_exception() _GLIBCXX_USE_NOEXCEPT;
arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/6.3.0/bits/exception_ptr.h:      friend exception_ptr std::current_exception() _GLIBCXX_USE_NOEXCEPT;
arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/6.3.0/bits/exception_ptr.h:     return current_exception();
arm-none-linux-gnueabihf/arm-none-linux-    gnueabihf/include/c++/6.3.0/bits/nested_exception.h:    nested_exception()     noexcept : _M_ptr(current_exception()) { }

我用于Crosstool-ng的设置是:

arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ -v

Using built-in specs.
COLLECT_GCC=x-tools/arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++
COLLECT_LTO_WRAPPER=/home/builduser/x-tools/arm-none-linux-gnueabihf/libexec/gcc/arm-none-linux-gnueabihf/6.3.0/lto-wrapper
Target: arm-none-linux-gnueabihf
Configured with: /home/builduser/build/.build/src/gcc-6.3.0/configure 
--build=x86_64-build_pc-linux-gnu 
--host=x86_64-build_pc-linux-gnu 
--target=arm-none-linux-gnueabihf 
--prefix=/home/builduser/x-tools/arm-none-linux-gnueabihf 
--with-sysroot=/home/builduser/x-tools/arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/sysroot 
--enable-languages=c,c++ 
--with-float=hard 
--with-pkgversion='crosstool-NG crosstool-ng-1.23.0' 
--disable-sjlj-exceptions 
--enable-__cxa_atexit 
--disable-libmudflap 
--disable-libgomp 
--disable-libssp 
--disable-libquadmath 
--disable-libquadmath-support 
--disable-libsanitizer 
--disable-libmpx 
--with-gmp=/home/builduser/build/.build/arm-none-linux-gnueabihf/buildtools 
--with-mpfr=/home/builduser/build/.build/arm-none-linux-gnueabihf/buildtools 
--with-mpc=/home/builduser/build/.build/arm-none-linux-gnueabihf/buildtools 
--with-isl=/home/builduser/build/.build/arm-none-linux-gnueabihf/buildtools 
--disable-lto 
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++ -lm' 
--enable-threads=posix 
--enable-target-optspace 
--disable-plugin 
--disable-nls 
--disable-multilib 
--with-local-prefix=/home/builduser/x-tools/arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/sysroot 
--enable-long-long
Thread model: posix
gcc version 6.3.0 (crosstool-NG crosstool-ng-1.23.0) 

构建一个std :: array示例可以正常工作。

修改

如果我将CT_ARCH_CPU="cortex-a9"选项包含在我的crostool-ng配置中(在g ++中导致--with-cpu=cortex-a9),则std :: current_exception示例正常工作。

所以问题是:

为什么编译器应该生成cpu变量以及cpu变量被告知工具链(在运行时-mcpu与inbuild --with-cpu)的方式正在影响编译/链接的能力的std ::函数current_exception?

0 个答案:

没有答案