簡體   English   中英

如何在 M1 Mac 上安裝 ruby-odbc gem

[英]How to install ruby-odbc gem on M1 Mac

我正在嘗試在 M1 mac 上運行 rails 項目。 我必須使用 ruby 2.6.2 和 rails 5.2.3

我正在使用 rbenv 1.1.2 和 homebrew 3.0

當我運行bundle install時,出現此錯誤

An error occurred while installing ruby-odbc (0.99999), and Bundler cannot continue.
  Make sure that `gem install ruby-odbc -v '0.99999'` succeeds before bundling.

然后我運行gem install ruby-odbc -v '0.99999'

這導致另一個錯誤

ERROR:  Error installing ruby-odbc:
ERROR: Failed to build gem native extension.

current directory: /Users/david.lee/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/ruby- 
odbc-0.99999/ext
/Users/david.lee/.rbenv/versions/2.6.2/bin/ruby -I 
/Users/david.lee/.rbenv/versions/2.6.2/lib/ruby/2.6.0 -r ./siteconf20210208-46271-1tguvxe.rb 
extconf.rb
checking for version.h... no
checking for sql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/david.lee/.rbenv/versions/2.6.2/bin/$(RUBY_BASE_NAME)
    --with-odbc-dir
    --without-odbc-dir
    --with-odbc-include
    --without-odbc-include=${odbc-dir}/include
    --with-odbc-lib
    --without-odbc-lib=${odbc-dir}/lib
ERROR: sql.h not found

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/david.lee/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/ruby-odbc-0.99999/mkmf.log

當我stackoverflow這個錯誤時,我得到這篇文章告訴我brew install unixodbc ,所以我這樣做並嘗試再次bundle install ,這給了我同樣的錯誤。

所有與未安裝 sql.h 文件相關的 stackoverflow 帖子都不能解決我的問題。

如何安裝此 GEM?

感謝一位同事,我解決了這個問題。 您需要在將 gem 指向 unixodbc 目錄時安裝它

這是為我安裝它的線路

gem install ruby-odbc -- --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.9

要查找您的 unixodbc 路徑,請運行brew info unixodbc

這將為您提供 unixodbc 的路徑和版本號。 然后你把路徑和版本號放在合適的位置gem install ruby-odbc -- --with-odbc-dir=put your path and version number of unixodbc here

如果您在運行bundle命令時需要此功能,請執行以下操作:

bundle config build.odbc --with-odbc-dir=$(brew --prefix unixodbc)

當我遇到此錯誤時,上述解決方案均不適合我。 這對我有用:

bundle config set build.ruby-odbc --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.11

根據這個 StackOverflow 帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM