nishu2901
Posts: 4
Joined: Wed Apr 10, 2019 1:43 pm

Installation steps for clang on Rpi3 for std::thread with c++11 program

Thu Apr 11, 2019 3:41 am

I have a Rpi3 with following specs :

Code: Select all

pi@raspberrypi ~ $ cat /etc/debian_version
8.0
pi@raspberrypi ~ $ 
pi@raspberrypi ~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 4.4.7-v7+ #878 SMP Tue Apr 19 19:03:45 BST 2016 armv7l GNU/Linux

I want to install clang on it and followed this blog but it doesn't seem to work :
https://solarianprogrammer.com/2018/04 ... programs/

Code: Select all

pi@raspberrypi ~ $ echo 'export PATH=/usr/local/clang_8.0.0/bin:$PATH' >> .bashrc
pi@raspberrypi ~ $ echo 'export LD_LIBRARY_PATH=/usr/local/clang_8.0.0/lib:$LD_LIBRARY_PATH' >> .bashrc
pi@raspberrypi ~ $ source .bashrc
pi@raspberrypi ~ $ clang --version
clang: /lib/arm-linux-gnueabihf/libtinfo.so.5: no version information available (required by clang)
clang: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by clang)
pi@raspberrypi ~ $
I am not even able to run sudo apt-get update successfully

Code: Select all

W: Failed to fetch http://raspberrypi.collabora.com/dists/wheezy/InRelease  

W: Failed to fetch http://raspberrypi.collabora.com/dists/wheezy/Release.gpg  Could not resolve 'raspberrypi.collabora.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

Please help me how to install latest version of clang on Rpi3.

My end requirement is i want to execute my program below :

Code: Select all

#include <iostream>
#include <thread>

int main()
{
std::thread th([]() {
std::cout << "Hello, World!" << std::endl;
});

th.join();

return 0;
}
with commad :

Code: Select all

clang++ -o demo demo.cpp -lpthread -std=c++11
but i am expecting output :

Code: Select all

Hello Wold!
Earlier i had clang version :

Code: Select all

Raspbian clang version 3.5.0-10+rpi1 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
but the code above used to give unexpected error while execution :

Code: Select all

pi@raspberrypi ~ $ ./demo
pure virtual method called
terminate called without an active exception
Aborted
I came to conclusion the it is clang version 3.5 which doesn't go hand in hand with std::thread hence i am looking out for upgraded version of clang. https://www.raspberrypi.org/forums/vie ... ?t=131856

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Installation steps for clang on Rpi3 for std::thread with c++11 program

Thu Apr 11, 2019 11:16 am

Those entries for apt that fails belongs to even older version of Raspbian, Wheezy.. so they can be safely removed from your "/etc/apt/sources.list".

I dont think they prevent normal updates.. and I still will suggest that you start from scratch with a Raspbian Stretch image. Any up-to-date guide you will find will be based on Stretch and not Jessie.

Return to “Beginners”