Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to Building native extensions. on Mac OSX 10.13.6 #78

Closed
fascox opened this issue Sep 12, 2018 · 21 comments
Closed

Fail to Building native extensions. on Mac OSX 10.13.6 #78

fascox opened this issue Sep 12, 2018 · 21 comments

Comments

@fascox
Copy link

fascox commented Sep 12, 2018

Building native extensions. This could take a while...
ERROR: Error installing solargraph:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.3.0/gems/eventmachine-1.2.7/ext

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20180912-38268-nmeu8e.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/eventmachine-1.2.7 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-17/2.3.0/eventmachine-1.2.7/gem_make.out

@castwide
Copy link
Owner

It looks like you don't have the Ruby development headers installed. The easiest way I know to get them on OSX is to install XCode.

Relevant links:

https://stackoverflow.com/questions/761521/when-i-try-sudo-gem-install-json-i-get-the-following-error

https://kevinpotgieter.wordpress.com/2012/12/06/ruby-gem-install-mkmf-rb-cant-find-header-files-for-ruby-problem/

@fascox fascox closed this as completed Sep 12, 2018
@fascox fascox reopened this Sep 12, 2018
@fascox
Copy link
Author

fascox commented Sep 12, 2018

xcode-select --install

and

sudo xcodebuild -license

solve the issue.

@fascox fascox closed this as completed Sep 12, 2018
@acalism
Copy link

acalism commented Jul 12, 2019

xcode-select --install

and

sudo xcodebuild -license

solve the issue.

After your commands, restarting macOS is required for me.

@xclidongbo
Copy link

macos 10.14.6.
same error.

@naffan2014
Copy link

same error

@Calebvh
Copy link

Calebvh commented Sep 25, 2019

Same error, (trying to install Jazzy)
current directory: /Library/Ruby/Gems/2.3.0/gems/redcarpet-3.5.0/ext/redcarpet
xcode-select --install
and
sudo xcodebuild -license
and then subsequent restart have not worked, any suggestions?

@castwide
Copy link
Owner

@Calebvh
Copy link

Calebvh commented Sep 25, 2019

Unfortunately I already have them installed, any other ideas?

@castwide
Copy link
Owner

This might be specific to MacOS 10.14. Apparently some development files got moved, or stopped getting installed by default, or...something. A couple of people have recommended running some variation of this:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

References:

@Calebvh
Copy link

Calebvh commented Sep 25, 2019

Yes, I was just about to post.
navigating to that package location and then entering:
sudo installer -pkg macOS_SDK_headers_for_macOS_10.14.pkg -target / 
This did the trick for me, thanks for your help!

@ChrisMash
Copy link

Running the .pkg in ~/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg worked for me, so thanks for the tips!

Incidentally a colleague of mine didn't have that packages folder on his machine. I'd install the Xcode 11 update from the App Store and he'd deleted and installed from the download from the apple developer site, so there may be a difference for people if they don't use the App Store (maybe you can get the pkg from the apple developer site downloads page?)

@jasonivers
Copy link

Installing the package fixed that problem for me, but it's not picking up my RVM ruby version when I do bundle install now... even though ruby --version DOES display it. Any ideas?

@jkuebart
Copy link

jkuebart commented Oct 3, 2019

The cause is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running

ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'   

which on macOS 10.14 with Xcode 11 prints the non-existent path

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

There might still be a macOS 10.14 SDK in /Library/Developer/CommandLineTools/SDKs. It isn't necessary to pollute the system directories by installing the old header files as suggested above. Instead, by pointing the SDKROOT environment variable to it, the appropriate ruby2.3 headers will be found:

SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/
export SDKROOT
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

This should now correctly print

/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk//System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

Likewise, gem install should work when the SDKROOT environment variable is set.

@mackworth
Copy link

For me (Xcode 11 on Mojave as well), gem install didn't seem to use the SDKROOT, even though RBConfig returned the right value. This suggestion on StackOverflow worked instead, so I'm passing it on here:

sudo xcode-select --switch /Library/Developer/CommandLineTools
and then restore afterwards with
sudo xcode-select --switch /Applications/Xcode.app

Reference: https://stackoverflow.com/a/58231417/580850

@ccarpita
Copy link

ccarpita commented Feb 25, 2020

If you are on OSX 10.15+, the headers package is no longer available. I fixed this issue by setting SDKROOT in my shell configuration to the value provided by xcrun, which should be mostly future-proof:

export SDKROOT=$(xcrun --show-sdk-path)

davidwintermeyer added a commit to davidwintermeyer/textbook-curriculum that referenced this issue Mar 4, 2020
I was trying to install guard today and ran into an issue:

mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

I found this post - castwide/vscode-solargraph#78 - which suggested the problem is because my mac is 10.14 

I had to run this command which then allowed me to install guard.

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

I wanted to mention this to your team incase you want to include it, though you may not feel it is relevant to Ada students!

David
@boxabirds
Copy link

This might be specific to MacOS 10.14. Apparently some development files got moved, or stopped getting installed by default, or...something. A couple of people have recommended running some variation of this:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

References:

Thanks! I'm on 10.14.4 and this was still necessary.

@shengyongniu
Copy link

For me (Xcode 11 on Mojave as well), gem install didn't seem to use the SDKROOT, even though RBConfig returned the right value. This suggestion on StackOverflow worked instead, so I'm passing it on here:

sudo xcode-select --switch /Library/Developer/CommandLineTools
and then restore afterwards with
sudo xcode-select --switch /Applications/Xcode.app

Reference: https://stackoverflow.com/a/58231417/580850

Thank you sir!

@mineschan
Copy link

If you are on OSX 10.15+, the headers package is no longer available. I fixed this issue by setting SDKROOT in my shell configuration to the value provided by xcrun, which should be mostly future-proof:

export SDKROOT=$(xcrun --show-sdk-path)

Only this solve my issue! Salute Sir!

@nomasprime
Copy link

Nothing worked for me on 10.15.7.

@philippfrank
Copy link

None of the above worked on 10.15.7 (Catalina). However, I got it up and running using rbenv:

rbenv global 2.7.4
gem install solargraph

@castwide
Copy link
Owner

castwide commented Dec 5, 2021

Ruby on MacOS is frequently problematic, especially if you're using whatever janky version of Ruby ships with the OS, which often does not include the stuff you need to natively compile depenencies like Nokogiri. The problems are not limited to Solargraph. One common solution is to use rbenv, which Solargraph makes an effort to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests