Unable to compile gcc installed from Homebrew

I have command line tools installed:

% pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 16.2.0.0.1.1733547573
volume: /
location: /
install-time: 1739567437

Thus clang is installed here:

% whereis g++
g++: /usr/bin/g++

I also have installed gcc from homebrew:

% /opt/homebrew/bin/g++-14 --version
g++-14 (Homebrew GCC 14.2.0_1) 14.2.0
Copyright (C) 2024 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.

However, I still cannot compile any c++ code, even the simplest one:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!" << endl;
    return 0;
}

It returned this error:

% /opt/homebrew/bin/g++-14 ~/Downloads/try.cpp 
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/lib/libSystem.tbd' for architecture arm64
collect2: error: ld returned 1 exit status

It seems to be command line tools related. But I've already installed the most recent version of CLT and gcc. Additionally, clang can compile the same code:

% /usr/bin/g++ ~/Downloads/try.cpp 
% ./a.out 
Hello World!

What else shall I do to make this g++ compiler work?

Answered by DTS Engineer in 827639022

DTS doesn’t support third-party tools, and that includes Homebrew and GCC, but I can at least explain the error you’re getting.

ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/lib/libSystem.tbd' for architecture arm64

This error is coming from the Apple linker, ld. That linker is being run by the GCC compiler driver. The linker is complaining about the stub libraries it’s been passed by the compiler driver. See An Apple Library Primer for an explanation as to what a stub library is.

My best guess is that there’s some sort of tools / SDK mixup. The compiler driver is running a version of the linker with stub libraries from an SDK that’s newer, or possibly older, than that’s supported by that linker. The fact that you’re on an M1 Mac, where the minimum OS version is macOS 11, and you’re using the macOS 10.15 SDK, may well be a smoking gun.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

BTW, I have mac silicon M1:

% uname -m
arm64

and macOS = Sequoia:

% sw_vers
ProductName:		macOS
ProductVersion:		15.3.1
BuildVersion:		24D70

DTS doesn’t support third-party tools, and that includes Homebrew and GCC, but I can at least explain the error you’re getting.

ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/lib/libSystem.tbd' for architecture arm64

This error is coming from the Apple linker, ld. That linker is being run by the GCC compiler driver. The linker is complaining about the stub libraries it’s been passed by the compiler driver. See An Apple Library Primer for an explanation as to what a stub library is.

My best guess is that there’s some sort of tools / SDK mixup. The compiler driver is running a version of the linker with stub libraries from an SDK that’s newer, or possibly older, than that’s supported by that linker. The fact that you’re on an M1 Mac, where the minimum OS version is macOS 11, and you’re using the macOS 10.15 SDK, may well be a smoking gun.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Unable to compile gcc installed from Homebrew
 
 
Q