3

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?

zeroclaim
  • 57
  • 2
  • 7

3 Answers3

3

You needd to add :

/usr/local/opt/binutils/bin
Philippe
  • 20,025
  • 2
  • 23
  • 32
  • 1
    The question doesn't give any environment info, if your mac is M1 based and homebrew is native, then the corresponding path will be `/opt/homebrew/Cellar/binutils/2.37/bin`(change 2.37 to the version of binutils you installed) – Steve Lau Mar 30 '22 at 04:00
  • Use this path on Mac M1 `/opt/homebrew/opt/binutils/bin`. – Mingjie Li Sep 27 '22 at 03:57
1

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

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
0

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
Sachin
  • 1,460
  • 17
  • 24