如何解决 libgomp.spec 在尝试使用 ruby 2.3.8 安装 rmagick gem 时丢失的问题 | Rails 3.2.22.5 |亚马逊 Linux 2018.03

how to resolve libgomp.spec missing while attempting to install rmagick gem with ruby 2.3.8 | Rails 3.2.22.5 | Amazon Linux 2018.03

尝试在 Amazon Linux 版本 2018.03

上安装 rmagick 时出错

yum install ImageMagick

之后

尝试gem install rmagick 会导致以下错误。任何 rmagic gem 版本都会发生这种情况。

    Amazon Linux version: 2018.03
    AMI Profile: base
    https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/

[user@ip-x-x-x-x]$ gem install rmagick

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

current directory: /home/user/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rmagick-4.0.0/ext/RMagick
/home/user/.rbenv/versions/2.3.8/bin/ruby -r ./siteconf20200310-7185-ka0l3b.rb extconf.rb
checking for brew... no
checking for pacman... no
checking for gcc... yes
checking for pkg-config... yes
checking for outdated ImageMagick version (<= 6.7.7)... no
checking for __GNUC__... *** 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=/home/user/.rbenv/versions/2.3.8/bin/$(RUBY_BASE_NAME)
/home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:571:in `block in try_compile'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:524:in `with_werror'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:571:in `try_compile'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:835:in `macro_defined?'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:974:in `block in have_macro'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
    from /home/user/.rbenv/versions/2.3.8/lib/ruby/2.3.0/mkmf.rb:973:in `have_macro'
    from extconf.rb:119:in `configure_compile_options'
    from extconf.rb:19:in `initialize'
    from extconf.rb:361:in `new'
    from extconf.rb:361:in `<main>'

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

  /home/user/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/rmagick-4.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/user/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rmagick-4.0.0 for inspection.
Results logged to /home/user/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/rmagick-4.0.0/gem_make.out

rmagick 4.0.0 内的附加信息mkmf.rb

find_executable: checking for brew... -------------------- no

--------------------

find_executable: checking for pacman... -------------------- no

--------------------

find_executable: checking for gcc... -------------------- yes

--------------------

find_executable: checking for pkg-config... -------------------- yes

--------------------

configure_compile_options: checking for outdated ImageMagick version (<= 6.7.7)... -------------------- no

Detected ImageMagick version: 6.7.8
--------------------

"gcc -o conftest -I/home/user/.rbenv/versions/2.3.8/include/ruby-2.3.0/x86_64-linux -I/home/user/.rbenv/versions/2.3.8/include/ruby-2.3.0/ruby/backward -I/home/user/.rbenv/versions/2.3.8/include/ruby-2.3.0 -I.  -fopenmp -I/usr/include/ImageMagick    -fopenmp -I/usr/include/ImageMagick   conftest.c  -L. -L/home/user/.rbenv/versions/2.3.8/lib -Wl,-rpath,/home/user/.rbenv/versions/2.3.8/lib  -lMagickCore      -lMagickCore    -Wl,-rpath,/home/user/.rbenv/versions/2.3.8/lib -L/home/user/.rbenv/versions/2.3.8/lib -lruby-static  -lpthread -ldl -lcrypt -lm   -lc"
gcc: error: libgomp.spec: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

libgomp.spec 文件在预期位置不可用。为了解决这个问题,我们必须将 libgomp.spec 从 gcc 6.4.1 符号链接到 /usr/lib64/ 目录

ln -s /usr/lib/gcc/x86_64-amazon-linux/6.4.1/libgomp.spec /usr/lib64/libgomp.spec
ln -s /usr/lib/gcc/x86_64-amazon-linux/6.4.1/libgomp.a /usr/lib64/libgomp.a
ln -s /usr/lib64/libgomp.so.1.0.0 /usr/lib64/libgomp.so

感谢@3D0G 提供的解决方案post:

gcc: error: libgomp.spec: No such file or directory with Amazon Linux 2017.09.1

添加此问题/答案以便更轻松地找到有关 rmagick gem 安装问题的解决方案。