简体   繁体   中英

What is the difference between c++ and g++ on Mac OS X (CommandLineTools)?

I see that c++ and g++ are mostly the same. Can they be used interchangably? When they will be different?

$ c++ --version
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ which c++
/Library/Developer/CommandLineTools/usr/bin/c++
$ which g++
/Library/Developer/CommandLineTools/usr/bin/g++

On MacOS, c++ is a symbolic link to the clang++ binary. In your case both c++ and g++ are the same Clang compiler for C++ (ie the LLVM compiler is being masqueraded as the GNU g++ compiler).

If you HAD installed the GCC compiler for C++ (more commonly known as g++), the differences between c++ and g++ would have been the differences between clang and gcc compilers. For example see this question or this compiler support table .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM