2

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.0

which 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.

2
+50

I followed the same article but with little changes:

  1. execute ldconfig after setting LD_LIBRARY_PATH.
  2. change the "18.04" in the url to "16.04".

The installation was:

apt install build-essential xz-utils curl
curl -SL http://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz | 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
ldconfig

Then 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_test

Execution of object file will give correct output:

# ./if_test
Local variable a is < 8

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.