How to set Clang 3.9 as the default in Zesty?

8,993

Solution 1

This answer pointed me in the right direction:

sudo update-alternatives --install \
    /usr/bin/clang++ clang++ /usr/lib/llvm-3.9/bin/clang++ 100
sudo update-alternatives --install \
    /usr/bin/clang clang /usr/lib/llvm-3.9/bin/clang 100

After running those two commands, the build was able to continue.

Solution 2

To build on the accepted answer, If you have multiple versions of clang, it may be in your best interest to make clang++ dependent on clang so that all you need to do is update clang to a different version and the version of clang++ follows suit.

You can do this using the --slave option of update-alternatives. So something like this:

sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.9 100 \
   --slave /usr/bin/clang++ clang++ /usr/bin/clang++-3.9

You can of course do it for other versions:

sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-4.0 100 \
   --slave /usr/bin/clang++ clang++ /usr/bin/clang++-4.0

sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 100 \
   --slave /usr/bin/clang++ clang++ /usr/bin/clang++-5.0

To switch versions, you just type:

sudo update-alternatives --config clang

Enter a selection and both clang and clang++ will be automatically switched to the same versions.

The same idea applies to GCC if you also have multiple versions of that, you can use this method to configure gcc and g++.

Errors:

update-alternatives: error: alternative clang++ can't be slave of clang: it is a master alternative

You may get this error when you try to run the above commands. No worries, it just means that you already configured clang++ on it's own as an alternative, so you will need to remove that alternative before the above will work. You can do so with the command:

sudo update-alternatives --remove clang++ /usr/bin/clang++-3.9

Do this for each version of clang++, then after removing them all, try again.

Sources:

Share:
8,993

Related videos on Youtube

Nathan Osman
Author by

Nathan Osman

Email: [email protected] I am both an Ubuntu user and Ubuntu member. By profession, I am a software developer and I work with C++, Python, and (more recently) Go. I enjoy tinkering with different things like motion tracking in Blender, creating an Android app for time-lapse photography, or writing Linux kernel modules. - 2buntu - community blog that I sometimes contribute to - NitroShare - a cross-platform network file transfer utility - REST Easy - Firefox add-on for analyzing HTTP responses

Updated on September 18, 2022

Comments

  • Nathan Osman
    Nathan Osman over 1 year

    Zesty ships with multiple versions of Clang. The clang Install clang package depends on both clang-3.9 Install clang-3.9 and clang-4.0 Install clang-4.0. It appears that Clang 4 is used by default:

    $ clang --version
    clang version 4.0.0-1ubuntu1 (tags/RELEASE_400/rc1)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    

    However, I need Clang 3.9 to be the default version. I am unable to compile UnrealEngine because of this:

    UnrealBuildTool Exception: ERROR: This version of the Unreal Engine can only be
        compiled with clang 3.9, 3.8, 3.7, 3.6 and 3.5. clang 4.0.0 may not build it -
        please use a different version.
    

    How can I go about this?

    • Grayson Kent
      Grayson Kent about 7 years
      Looking through the source code, it just defaults to whatever is in your PATH and CPATH and then does a check on the first version found there. Are you okay temporarily changing those paths to build this?
    • Nathan Osman
      Nathan Osman about 7 years
      @GraysonKent I found an answer and posted it below, but changing the PATH would have worked as well, I'm sure.