如何在 M1 Mac 上安装 ruby​​-odbc gem

时间:2021-02-08 20:30:12

标签: ruby-on-rails ruby rubygems

我正在尝试在 M1 mac 上运行一个 rails 项目。 我必须使用 ruby​​ 2.6.2 和 rails 5.2.3

我正在使用 rbenv 1.1.2 和自制软件 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

当我计算溢出这个错误时,我得到这个 post,它告诉我 brew install unixodbc,所以我这样做并再次尝试 bundle install,这给了我同样的错误。

所有与未安装 sql.h 文件相关的 stackoverflow 帖子都不能解决我的问题。

我该如何安装这个 GEM?

1 个答案:

答案 0 :(得分:0)

感谢一位同事,我解决了这个问题。 您需要在将 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