7

I was trying to cross-compile dlib for Raspberry Pi, using the arm-linux-gnueabihf compiler.

After successful runs of cmake and make -j4, I ran python setup.py bdist_wheel --repackage, which created the nencessary .so files which I later copied to my Pi's /usr/lib using scp.

Now when I run import dlib in IDLE, I get the following error:

ImportError: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by dlib/dlib.so)

Here's the ouput of strings /usr/lib/libstdc++.so.6 | grep GLIBCXX:

GLIBCXX_3.4 GLIBCXX_3.4.1 GLIBCXX_3.4.2 GLIBCXX_3.4.3 GLIBCXX_3.4.4 GLIBCXX_3.4.5 GLIBCXX_3.4.6 GLIBCXX_3.4.7 GLIBCXX_3.4.8 GLIBCXX_3.4.9 GLIBCXX_3.4.10 GLIBCXX_3.4.11 GLIBCXX_3.4.12 GLIBCXX_3.4.13 GLIBCXX_3.4.14 GLIBCXX_3.4.15 GLIBCXX_3.4.16 GLIBCXX_3.4.17 GLIBCXX_3.4.18 GLIBCXX_3.4.19 GLIBCXX_3.4.20

This means that the error is legitimate, but my libstdc++ is already at its newest version on the Pi. What can I do to get that 3.4.22 version installed on the Pi? Or maybe, if it's possible, to compile it again against 3.4.20? How can I set a compiler flag for that?

code
  • 211
  • 1
  • 2
  • 4

1 Answers1

4

It appears you used a g++ 6 cross-compiler (default install on Debian 9?) then attempted to run the resulting binary on Raspbian 8 Jessie. You can see gcc's symbol versioning guide here where g++ 4.9 ties to GLIBCXX_3.4.20 and g++ 6 to GLIBCXX_3.4.22.

What can I do to get that 3.4.22 version installed on the Pi?

Perhaps the most straightforward approach is to update to Raspbian 9 Stretch. It's based on gcc/g++ 6.3.

Or maybe, if it's possible, to compile it again against 3.4.20? How can I set a compiler flag for that?

If it's not convenient to upgrade your Pi, you can instead use a different cross-compiler. You cannot merely use a flag because g++ is quite intertwined with libstdc++'s version.

git clone https://github.com/raspberrypi/tools

At the time of writing that toolchain is geared for gcc 4.9 / Raspbian 8 Jessie. Or if you prefer to continue using system packages installed via apt, try this:

sudo apt remove g++-arm-linux-gnueabihf
sudo apt install g++-4.9-arm-linux-gnueabihf
sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc-4.9 10
sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/arm-linux-gnueabihf-g++-4.9 10
sudo update-alternatives --config arm-linux-gnueabihf-gcc
sudo update-alternatives --config arm-linux-gnueabihf-g++

Caveat: that last approach may result in a toolchain that defaults to ARMv7 code, which works for the Pi 2 and 3, but not Pi classic/B+/Zero.

jdonald
  • 2,972
  • 14
  • 39