I can't for the life of me figure out how to get C++17 to work on Ubuntu 16.04.
This works on Ubuntu 18.04:
sudo apt-get update
sudo apt-get install clang-6.0which installs the C++17 standard library headers in /usr/include/c++/7. However, when I run the same commands in Ubuntu 16.04, I get C++14 headers in /usr/include/c++/5, and C++17 features won't compile.
I tried following this as well to install clang-7, but that led to the following error:clang: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 'GLIBCXX_3.4.22' not found (required by clang)
Apologies if this is a dumb question; I am new to this stuff and am probably missing something obvious.
1 Answer
I followed the same article but with little changes:
- execute
ldconfigafter settingLD_LIBRARY_PATH. - change the "18.04" in the url to "16.04".
The installation was:
apt install build-essential xz-utils curl
curl -SL | tar -xJC .
cp -r clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/ /usr/local/clang-7.0.1
export LD_LIBRARY_PATH=/usr/local/clang-7.0.1/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/clang-7.0.1/bin:$PATH
ldconfigThen created if_test.cpp:
#include <iostream>
int main() { // if block with init-statement: if(int a = 5; a < 8) { std::cout << "Local variable a is < 8\n"; } else { std::cout << "Local variable a is >= 8\n"; } return 0;
}The source code was compiled by following instruction:
clang++ -std=c++17 -stdlib=libc++ -Wall -pedantic if_test.cpp -o if_testExecution of object file will give correct output:
# ./if_test
Local variable a is < 8