How to set clang++ as the c++ compiler?

17,766

I think that alternatives are the wrong approach here. More generally, I think changing the system default is really the wrong approach. Rather than changing things at that level, I suggest

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

Unless something goes out of its way to break it, this will work with almost all make systems.

If you want this to be the default systemwide, you could put this in the system bash startup scripts in /etc/. But, again, I don't think that's a generally good idea. Better to make the choice on a per user — or per-project — basis.

Share:
17,766

Related videos on Youtube

Jephir
Author by

Jephir

Updated on September 18, 2022

Comments

  • Jephir
    Jephir almost 2 years

    I'm trying to set clang++ as the system C++ compiler on Fedora 18. I have installed clang and added it to alternatives but it doesn't appear to be working.

    [user@localhost ~]$ alternatives --display c++
    c++ - status is auto.
     link currently points to /usr/bin/clang++
    /usr/bin/clang++ - priority 1
    Current `best' version is /usr/bin/clang++.
    [user@localhost ~]$ c++ --version
    c++ (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
    Copyright (C) 2012 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    c++ still appears to be using gcc even though alternatives is configured to use clang++.


    type -a c++ output:

    [user@localhost ~]$ type -a c++
    c++ is /usr/bin/c++
    c++ is /bin/c++
    
    • jordanm
      jordanm about 11 years
      What does type -a c++ say?
    • Jephir
      Jephir about 11 years
      Added type -a c++ output to question.