MacOS 12.1 cannot find my brew install of GNU binutils

Viewed 1112

I want to use GNU binutils to inspect an executable on MacOS 12.1. I did a

% brew install binutils

and it seemed to go fine. First I tried just a

% readelf <executable>

but was given:

zsh: command not found: readelf

Then I tried checking on binutils itself:

% binutils -v

which gave me

zsh: command not found: binutils

I tried adding both

/usr/local/opt/binutils

and

/usr/local/Cellar/binutils

to my $PATH and restarting zsh. The filepaths were in my $PATH, and homebrew had put 'binutils' in the expected locations. But

% binutils -v

still gives me

zsh: command not found: binutils

. Has anyone gotten binutils to work on Mac? What am I missing?

3 Answers

You needd to add :

/usr/local/opt/binutils/bin

Check if Xcode is installed or not:

$ gcc --version

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

$ brew doctor

$ brew update

The path /usr/local/opt/binutils/bin should be added to your PATH environment variable.

You probably didn't notice the output from brew install binutils:

binutils is keg-only, which means it was not symlinked into /usr/local, because Apple's CLT provides the same tools.

If you need to have binutils first in your PATH, run: echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> /Users/ipellegrini/.bash_profile

For compilers to find binutils you may need to set: export LDFLAGS="-L/usr/local/opt/binutils/lib" export CPPFLAGS="-I/usr/local/opt/binutils/include"

So should be enough to:

  • ⤵️
    run echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile in order to add the bin folder to PATH, automatically, every time you open a new command-line shell.

  • close the current shell and open a new one, for triggering the .bash_profile and making the command available for use.

  • run which readelf to ensure that your desired command is found & reachable

Enjoy

Related