2

Ubuntu 14.04. I've installed gcc-arm-linux-gnueabihf, g++-arm-linux-gnueabihf (tried 4.8 and 4.9 from utopic).

Code that uses std::thread:

#include <iostream>
#include <chrono>
#include <future>

void secondList()
{
    const std::chrono::seconds twoSeconds(2);

    for (size_t i = 0; i != 300; ++i)
    {
        std::this_thread::sleep_for(twoSeconds);
        std::cout << "2s\n";
    }
}

int main(int, const char *[])
{
    auto secondThr = std::async(std::launch::async, secondList);

    return 0;
}

Compiling with:

arm-linux-gnueabihf-g++ --std=c++11 main.cpp -lpthread -o main

On RPI it fails:

pi@raspberrypi ~ $ ./main 
pure virtual method called
terminate called without an active exception
Aborted

Compiling on RPI works:

pi@raspberrypi ~ $ g++ --std=c++0x main.cpp -lpthread -o main

Pi image 2015-02-16-raspbian-wheezy, g++ on Pi (Debian 4.6.3-14+rpi1) 4.6.3.

I've tried compiler options -mcpu=cortex-a7, -mcpu=cortex-a8 and -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_{1,2,4,8} that were mentioned in similar questions.

Also tried g++ from ppa: http://ppa.launchpad.net/linaro-maintainers/toolchain/ubuntu precise

Why it is happening and how to get a cross-compiler that works?

  • I think this is a pure programming question and should be asked on Stack Overflow. – muru Apr 22 '15 at 13:11
  • 2
    I think this is much more about the compiler than the language and programming. That's fairly Ubuntu IMO. – Oli Apr 22 '15 at 13:34
  • People on stackoverflow have no idea. The most voted answers are like "take toolchain from some git repository, compile it and then rsync to /lib and /usr on Pi". It is horrible since the g++-arm-linux-gnueabihf almost works both for Pi and bq phone except for that locking bug on Pi. – Velkan Apr 22 '15 at 13:56
  • Velkan I don't see a post from you on SO. @Oli SO also encompasses the tools involved in programming - including the compiler. – muru Apr 23 '15 at 21:49
  • Is this a Raspberry Pi 1 or 2? Also, what is the output of "uname -a" on the Pi? Not all kernels are hard-float (the "hf" in "armhf"). – Nathan Osman Apr 30 '15 at 20:09
-1

With jessie-based image it works.

  • Unfortunately, it's not work on my jessie-based image. I'm cross compile from OSX, it seems it's compiler's bug. – Alston Feb 12 '17 at 16:23
-1

Add this to the command line for linking,

-Wl,--whole-archive -lpthread -Wl,--no-whole-archive

See this message for explanations, https://gcc.gnu.org/ml/gcc-help/2010-05/msg00029.html It said to be a problem of TLS, but maybe it's related incomplete symbols linked from static libpthread.

-1

It can probably be fixed by adding -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 to the command line flags.

The root cause and fix are described here: https://raspberrypi.stackexchange.com/questions/48225/whats-causing-these-crashes-after-cross-compiling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.