teratail header banner
teratail header banner
質問するログイン新規登録
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

310閲覧

M1 Mac 2020 (Ventura 13.6) で ruby-filemagic 0.7.2 がインストールできない

noraworld

総合スコア3

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2024/10/12 05:58

0

0

実現したいこと

Rails アプリケーションで使用する "ruby-filemagic" をインストールしたいです。

発生している問題・分からないこと

"ruby-filemagic" がインストールできません。

エラーメッセージ

error

1Fetching ruby-filemagic 0.7.2 2Installing ruby-filemagic 0.7.2 with native extensions 3Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 4 5 current directory: /Users/kosuke/Workspace/diary-system/vendor/bundle/ruby/2.5.0/gems/ruby-filemagic-0.7.2/ext/filemagic 6/Users/kosuke/.asdf/installs/ruby/2.5.1/bin/ruby -r ./siteconf20241012-57499-jpkdgf.rb extconf.rb --with-magic-dir=/opt/homebrew/opt/libmagic 7--with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib 8checking for -lgnurx... no 9checking for magic_open() in -lmagic... no 10*** ERROR: missing required library to compile this module 11*** extconf.rb failed *** 12Could not create Makefile due to some reason, probably lack of necessary 13libraries and/or headers. Check the mkmf.log file for more details. You may 14need configuration options. 15 16Provided configuration options: 17 --with-opt-dir 18 --without-opt-dir 19 --with-opt-include 20 --without-opt-include=${opt-dir}/include 21 --with-opt-lib 22 --without-opt-lib=${opt-dir}/lib 23 --with-make-prog 24 --without-make-prog 25 --srcdir=. 26 --curdir 27 --ruby=/Users/kosuke/.asdf/installs/ruby/2.5.1/bin/$(RUBY_BASE_NAME) 28 --with-magic-dir 29 --with-magic-include=${magic-dir}/include 30 --with-magic-lib=${magic-dir}/lib 31 --with-gnurx-dir 32 --without-gnurx-dir 33 --with-gnurx-include 34 --without-gnurx-include=${gnurx-dir}/include 35 --with-gnurx-lib 36 --without-gnurx-lib=${gnurx-dir}/lib 37 --with-gnurxlib 38 --without-gnurxlib 39 --with-magiclib 40 --without-magiclib 41 42To see why this extension failed to compile, please check the mkmf.log which can be found here: 43 44 /Users/kosuke/Workspace/diary-system/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-22/2.5.0/ruby-filemagic-0.7.2/mkmf.log 45 46extconf failed, exit code 1 47 48Gem files will remain installed in /Users/kosuke/Workspace/diary-system/vendor/bundle/ruby/2.5.0/gems/ruby-filemagic-0.7.2 for inspection. 49Results logged to /Users/kosuke/Workspace/diary-system/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-22/2.5.0/ruby-filemagic-0.7.2/gem_make.out 50 51An error occurred while installing ruby-filemagic (0.7.2), and Bundler cannot continue. 52Make sure that `gem install ruby-filemagic -v '0.7.2' --source 'https://rubygems.org/'` succeeds before bundling. 53 54In Gemfile: 55 ruby-filemagic

該当のソースコード

特になし
特になし

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

ネットで調べると "libmagic" が必要とかパスを指定する必要があるという情報しか出てこないのですが、libmagic はインストールされていますしパスも指定していますがインストールできません。libmagic の再インストールも試しましたが駄目です。

brew reinstall libmagic gem install -v 0.7.2 ruby-filemagic -- \ --with-magic-include=/opt/homebrew/include \ --with-magic-lib=/opt/homebrew/lib gem install ruby-filemagic -v '0.7.2' --source 'https://rubygems.org/' -- --with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib gem install -v 0.7.2 ruby-filemagic -- --with-magic-prefix=/opt/homebrew gem install -v 0.7.2 ruby-filemagic -- --with-magic-dir=$(brew --prefix libmagic) bundle config --local build.ruby-filemagic "--with-magic-dir=$(brew --prefix libmagic)" gem install ruby-filemagic -v '0.7.2' --source 'https://rubygems.org/' -- --with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib/ gem install ruby-filemagic -v 0.7.2 -- \ --with-magic-lib=$(brew --prefix)/lib \ --with-magic-include=$(brew --prefix)/include brew link libmagic gem install ruby-filemagic -v '0.7.2' --source 'https://rubygems.org/' -- --with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib/

試した情報は以下のとおりです。

補足

特になし

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

noraworld

2024/10/12 06:00

"/Users/kosuke/Workspace/diary-system/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-22/2.5.0/ruby-filemagic-0.7.2/mkmf.log" の中身は以下のとおりです。 ``` have_library: checking for -lgnurx... -------------------- no "clang -o conftest -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/x86_64-darwin22 -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0 -I. -I/opt/local/include -I/usr/local/include -I/usr/include -I/opt/homebrew/opt/libmagic/include -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include -I/opt/homebrew/opt/imagemagick@6/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -Wno-error=implicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/local/lib -L/usr/local/lib -L/usr/lib -L/opt/homebrew/opt/libmagic/lib -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/homebrew/opt/imagemagick@6/lib -fstack-protector -lruby.2.5.1 -lpthread -ldl -lobjc " ld: warning: search path '/opt/local/lib' not found checked program was: /* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char **argv) 4: { 5: return 0; 6: } /* end */ "clang -o conftest -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/x86_64-darwin22 -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0 -I. -I/opt/local/include -I/usr/local/include -I/usr/include -I/opt/homebrew/opt/libmagic/include -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include -I/opt/homebrew/opt/imagemagick@6/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -Wno-error=implicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/local/lib -L/usr/local/lib -L/usr/lib -L/opt/homebrew/opt/libmagic/lib -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/homebrew/opt/imagemagick@6/lib -fstack-protector -lruby.2.5.1 -lgnurx -lpthread -ldl -lobjc " ld: warning: search path '/opt/local/lib' not found ld: library 'gnurx' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) checked program was: /* begin */ 1: #include "ruby.h" 2: 3: /*top*/ 4: extern int t(void); 5: int main(int argc, char **argv) 6: { 7: if (argc > 1000000) { 8: printf("%p", &t); 9: } 10: 11: return 0; 12: } 13: 14: int t(void) { ; return 0; } /* end */ -------------------- have_library: checking for magic_open() in -lmagic... -------------------- no "clang -o conftest -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/x86_64-darwin22 -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0 -I. -I/opt/local/include -I/usr/local/include -I/usr/include -I/opt/homebrew/opt/libmagic/include -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include -I/opt/homebrew/opt/imagemagick@6/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -Wno-error=implicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/local/lib -L/usr/local/lib -L/usr/lib -L/opt/homebrew/opt/libmagic/lib -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/homebrew/opt/imagemagick@6/lib -fstack-protector -lruby.2.5.1 -lmagic -lpthread -ldl -lobjc " conftest.c:13:57: error: use of undeclared identifier 'magic_open' int t(void) { void ((*volatile p)()); p = (void ((*)()))magic_open; return !p; } ^ 1 error generated. checked program was: /* begin */ 1: #include "ruby.h" 2: 3: /*top*/ 4: extern int t(void); 5: int main(int argc, char **argv) 6: { 7: if (argc > 1000000) { 8: printf("%p", &t); 9: } 10: 11: return 0; 12: } 13: int t(void) { void ((*volatile p)()); p = (void ((*)()))magic_open; return !p; } /* end */ "clang -o conftest -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/x86_64-darwin22 -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include/ruby-2.5.0 -I. -I/opt/local/include -I/usr/local/include -I/usr/include -I/opt/homebrew/opt/libmagic/include -I/Users/kosuke/.asdf/installs/ruby/2.5.1/include -I/opt/homebrew/opt/imagemagick@6/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -Wno-error=implicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/local/lib -L/usr/local/lib -L/usr/lib -L/opt/homebrew/opt/libmagic/lib -L. -L/Users/kosuke/.asdf/installs/ruby/2.5.1/lib -L/opt/homebrew/opt/imagemagick@6/lib -fstack-protector -lruby.2.5.1 -lmagic -lpthread -ldl -lobjc " ld: warning: search path '/opt/local/lib' not found ld: warning: ignoring file '/opt/homebrew/Cellar/libmagic/5.45/lib/libmagic.1.dylib': found architecture 'arm64', required architecture 'x86_64' ld: Undefined symbols: _magic_open, referenced from: _t in conftest-ad4b24.o clang: error: linker command failed with exit code 1 (use -v to see invocation) checked program was: /* begin */ 1: #include "ruby.h" 2: 3: /*top*/ 4: extern int t(void); 5: int main(int argc, char **argv) 6: { 7: if (argc > 1000000) { 8: printf("%p", &t); 9: } 10: 11: return 0; 12: } 13: extern void magic_open(); 14: int t(void) { magic_open(); return 0; } /* end */ -------------------- ```
winterboum

2024/10/12 07:55

インストールした libmagic.1.dylib はどこに有りますか? 「パスも指定していますが」とありますが、どの様に指定したのか書いてください。翻訳しないで 入力した通りに
noraworld

2024/10/12 08:57 編集

libmagic.1.dylib は /opt/homebrew/Cellar/libmagic/5.45/lib 以下にありますが /opt/homebrew/lib にもシンボリックリンクが貼られています。 パスの指定は本文にも記載していますし翻訳もしていないのですが、--with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib や --with-magic-dir=$(brew --prefix libmagic) のように指定しました。 ちなみにシンボリックリンクではなく実体を参照しても結果は同じでした。
winterboum

2024/10/12 13:29 編集

「lib 以下にあります」とのことですが 「lib にあります」ではない? 「以下」にある? /opt/homebrew/lib/libmagic.1.dylib があるのですね?
noraworld

2024/10/12 13:35

はい、/opt/homebrew/lib/libmagic.1.dylib があります。ただしこれはシンボリックリンクで、実体は /opt/homebrew/Cellar/libmagic/5.45/lib/libmagic.1.dylib です。ls -l で確認すると /opt/homebrew/lib/libmagic.1.dylib -> ../Cellar/libmagic/5.45/lib/libmagic.1.dylib のようにリンクが貼られています。
melian

2024/10/12 14:03

> ld: warning: ignoring file '/opt/homebrew/Cellar/libmagic/5.45/lib/libmagic.1.dylib': found architecture 'arm64', required architecture 'x86_64' と表示されているので、libmagic.1.dylib は ARM64 版で、実際に必要なのは x86_64 版ではないでしょうか。
noraworld

2024/10/12 15:48

なるほど、このライブラリだけ x86_64 でインストールするとなると他のライブラリとの互換性が気になります。他のライブラリは arm64 でこれだけ x86_64 でアプリケーションを動作させることはできるのでしょうか? それからインストールする際にも x86_64 版の Homebrew をインストールしたりする必要があっていろいろ環境的にめんどくさい気がします。やはり M1 Mac (非 Docker、非仮想 Linux 環境) で ruby-filemagic を含む開発は現実的ではないのでしょうか?
technocore

2024/10/13 03:04

私の環境(M2/Macbook)ではとりあえずインストールできたようです。 動作確認はしていませんが。。。 % ruby -v ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23] % brew info libmagic ==> libmagic: stable 5.45 (bottled) Implementation of the file(1) command https://www.darwinsys.com/file/ Installed % gem list ruby-filemagic *** LOCAL GEMS *** ruby-filemagic (0.7.3)
noraworld

2024/10/13 04:19

Ruby のバージョンのところを見てもしやと思い、Ruby のバージョンを上げて試してみたらインストールできました。 環境構築をしようとしていたプロジェクトは古くて Ruby のバージョンが 2.5.1 (ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin22]) でした。これだとバージョンが古すぎて Ruby 自体も x86_64 のため各種ネイティブライブラリが x86_64 を要求するが arm64 との依存関係があるとインストールできない、ということだったみたいです。 手元に Ruby 3.0.7 (ruby 3.0.7p220 (2024-04-23 revision 724a071175) [arm64-darwin22]) の環境があったのでそちらで試したら動作しました。バージョン情報を載せていただいたおかげで気づけました、ありがとうございました。
melian

2024/10/13 04:25 編集

※ 解決済みのためコメントを削除
guest

回答1

0

自己解決

結論、Ruby のバージョンが古いことが原因でした。

環境構築をしようとしていたプロジェクトは古くて Ruby のバージョンが 2.5.1 (ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin22]) でした。これだとバージョンが古すぎて Ruby 自体も x86_64 のため各種ネイティブライブラリが x86_64 を要求するが arm64 との依存関係があるとインストールできない、ということだったみたいです。

shell

1> ruby -v 2ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin22] 3 4> gem -v 52.7.6 6 7> gem install ruby-filemagic 8(概要欄記載のエラーメッセージ)

手元に Ruby 3.0.7 (ruby 3.0.7p220 (2024-04-23 revision 724a071175) [arm64-darwin22]) の環境があったのでそちらで試したら動作しました。

shell

1> ruby -v 2ruby 3.0.7p220 (2024-04-23 revision 724a071175) [arm64-darwin22] 3 4> gem -v 53.2.33 6 7> gem install ruby-filemagic 8Fetching ruby-filemagic-0.7.3.gem 9Building native extensions. This could take a while... 10 11ruby-filemagic-0.7.3 [2022-01-07]: 12 13* Dockerfile to build native extension (pull request #26 by Pavel Lobashov). 14* Include paths for ARM-based Apple Macs (Apple Silicon) (pull request #35 by 15 @545ch4). 16 17Successfully installed ruby-filemagic-0.7.3 18Parsing documentation for ruby-filemagic-0.7.3 19Installing ri documentation for ruby-filemagic-0.7.3 20Done installing documentation for ruby-filemagic after 3 seconds 211 gem installed

投稿2024/10/13 04:23

noraworld

総合スコア3

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問