OSX 和 Linux 上的 g++ 编译器之间的主要区别是什么?

What are the major differences between g++ compiler on OSX and Linux?

我试图找到这个,但互联网上没有太多信息。但是有时我使用 premake 来制作 GNU makefile 并且有一些 link 选项在 OSX 上默认打开,比如 pthread 但在 linux.[=12= 上没有]

如果某处有关于它的文档,那将非常有帮助。

主要区别在于,除非您从 XCode 以外的其他来源安装了编译器,否则 OSX 上的 "g++" 可能是 clang:

$ path -l g++ gcc
lrwxr-xr-x  1 root  admin  23 Dec  6  2014 /opt/local/bin/g++ -> /opt/local/bin/g++-mp-5
-rwxr-xr-x  1 root  wheel  18176 Jul  8 22:52 /usr/bin/g++
lrwxr-xr-x  1 root  admin  23 Dec  6  2014 /opt/local/bin/gcc -> /opt/local/bin/gcc-mp-5
-rwxr-xr-x  1 root  wheel  18176 Jul  8 22:52 /usr/bin/gcc

$ /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 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ /usr/bin/gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

它提供不同的错误消息,并且通常不会 return 错误状态以显示与 g++ 相同的警告。

如果您通过 MacPorts 或自制软件安装 g++,差异 将是由于 g++ 版本的差异所致。