OS X Mountain Lion: gcc-4.2 No such file or direct

2019-01-16 18:31发布

Tried to install a gem on Mountain Lion and make couldn't find gcc-4.2:

kamil$ gem install posix-spawn -v '0.3.6'
Building native extensions.  This could take a while...
ERROR:  Error installing posix-spawn:
    ERROR: Failed to build gem native extension.

        /Users/kamil/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb
creating Makefile

make
compiling posix-spawn.c
make: gcc-4.2: No such file or directory
make: *** [posix-spawn.o] Error 1

3条回答
虎瘦雄心在
2楼-- · 2019-01-16 18:58

If you have Xcode installed, gcc should be available. Check where it is with:

kamil$ which gcc
/usr/bin/gcc

Then make a user-land symbolic link from gcc-4.2 to plain gcc:

kamil$ sudo ln -s ~/bin/gcc /usr/bin/gcc-4.2

(Ensure the user-land bind folder is in your path via export PATH=...:$HOME/bin in your .bash_profile or .zshrc.)

Gem installed fine afterwards.

查看更多
乱世女痞
3楼-- · 2019-01-16 19:01

As @Artur Bodera mentioned modern OSX will refuse to let you create the symlink in the systems /bin folder.

To avoid this simply create the symlink to your users bin folder

ln -s ~/bin/gcc /usr/bin/gcc-4.2

Don't forget to add the bin folder to your .zshrc or .bash_profile - e.g.

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$HOME/bin
查看更多
霸刀☆藐视天下
4楼-- · 2019-01-16 19:02

Install simply apple-gcc42 with brew. It generate gcc-4.2 .

brew install apple-gcc42

So we do not need symlinks, which apple update may remove.

Homebrew

查看更多
登录 后发表回答