Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is g++ linked to clang, not clang++, by the mac developer tools?

Tags:

I was just trying to explain to someone the difference between compiled and interpreted code, when I was greeted with a

main.cpp:1:10: fatal error: 'iostream' file not found

when calling g++ main.cpp for a simple hello world c++ file.

I looked into this a bit and found ...

JM:Desktop user$ which g++
/usr/local/bin/g++
JM:Desktop user$ ls -al /usr/local/bin/g++
lrwxr-xr-x  1 user  admin  47  4 Dez  2018 /usr/local/bin/g++ -> /Library/Developer/CommandLineTools/usr/bin/c++
JM:Desktop user$ ls -al /Library/Developer/CommandLineTools/usr/bin/c++
lrwxr-xr-x  1 root  wheel  5  3 Feb 20:29     /Library/Developer/CommandLineTools/usr/bin/c++ -> clang

...that g++ is linked to clang and not clang++ and I therefore call the C-compiler.

I just deleted the Developer tools and installed them again - same thing.

Is this normal or did something mess up my system? Does it make any sense? What am I missing?

Thanks for the help!

like image 572
Johannes Avatar asked Feb 03 '20 19:02

Johannes


People also ask

Does Mac use GCC or Clang?

Apple ships the clang/LLVM compiler with macOS. Clang is a "front-end" that can parse C , C++ and Objective-C down to something that LLVM (referred to as a "back-end") can compile. Clang/LLVM is located in /Applications/Xcode. app/somewhere.

Does macOS use Clang?

From Xcode 4.2, Clang is the default compiler for Mac OS X.

Is G ++ a Clang?

gcc and g++ are the traditional GNU compilers for C and C++ code. Recently, clang (and clang++) using LLVM has been gaining popularity as an alternative compiler.

Does Apple use Clang?

In the end, Apple chose to develop Clang, a new compiler front end that supports C, Objective-C and C++.


1 Answers

It may actually be Homebrew's fault somehow...

JM:Desktop user$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

/usr/local/bin is added by Homebrew.

'C++' for example links correctly to clang++ but it is in /usr/bin:

JM:Desktop user$ which c++
/usr/bin/c++

...and so is /usr/bin/g++.

I solved it by just deleting /user/local/bin/g++. The links are still strange.

like image 104
Johannes Avatar answered Sep 19 '22 22:09

Johannes