std::shared_future on Raspberry Pi toolchain

2019-03-30 00:27发布

问题:

I'm trying to cross-compile a large project for the Raspberry Pi. I'm using a toolchain built by crosstool-ng, gcc version 4.7.3. The compilation chokes when it sees std::shared_future. I get this error:

test.cpp:5:27: error: aggregate 'std::shared_future<int> xxx' has incomplete type and cannot be defined

And here's the source file that generates that error:

#include <future>

int main()
{
  std::shared_future<int> xxx;
  return 0;
}

This same source file compiles successfully on the Rapsberry Pi itself. Is this a bug in the crosstool toolchain? Is there a workaround? How can I get this to successfully compile?

回答1:

To have shared_future implementation class and not just the forward declaration, you must have the following preprocessor condition equal to true : #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) && (ATOMIC_INT_LOCK_FREE > 1)

According to your previous answer to @juanchopanza, it seems that you have the following part of the condition equal to true : if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) because it's necarry to have the implementation of thread class.

Finaly, we could say that this part of the condition is false ATOMIC_INT_LOCK_FREE > 1.



回答2:

I solved this problem with help from @backlash and the people on #gcc on Freenode. Crosstool-NG was building the toolchain for armv7, while the Raspberry Pi's compiler was compiling for armv6. Changing the "Architecture level" (Target options > Architecture level) to armv6 allowed me to compile the sample code posted in my original question. This option adds a --with-arch=armv6 to the configure flags for gcc. Hope this helps someone out in the future.