在 Ubuntu 17.10 上构建 puma 3.11.0 失败

在 Ubuntu 17.10 上构建 puma 3.11.0 失败

尝试使用以下命令安装 puma

sudo gem install puma -v '3.11.0'

收到以下消息:

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

    current directory: /var/lib/gems/2.3.0/gems/puma-3.11.0/ext/puma_http11
/usr/bin/ruby2.3 -r ./siteconf20180412-95606-8c9cui.rb extconf.rb
checking for BIO_read() in -lcrypto... *** 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=/usr/bin/$(RUBY_BASE_NAME)2.3
    --with-puma_http11-dir
    --without-puma_http11-dir
    --with-puma_http11-include
    --without-puma_http11-include=${puma_http11-dir}/include
    --with-puma_http11-lib
    --without-puma_http11-lib=${puma_http11-dir}/lib
    --with-openssl-dir
    --without-openssl-dir
    --with-openssl-include
    --without-openssl-include=${openssl-dir}/include
    --with-openssl-lib
    --without-openssl-lib=${openssl-dir}/lib
    --with-cryptolib
    --without-cryptolib
/usr/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 /usr/lib/ruby/2.3.0/mkmf.rb:541:in `try_link0'
    from /usr/lib/ruby/2.3.0/mkmf.rb:556:in `try_link'
    from /usr/lib/ruby/2.3.0/mkmf.rb:765:in `try_func'
    from /usr/lib/ruby/2.3.0/mkmf.rb:997:in `block in have_library'
    from /usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
    from /usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
    from /usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
    from /usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
    from /usr/lib/ruby/2.3.0/mkmf.rb:992:in `have_library'
    from extconf.rb:8:in `block in <main>'
    from extconf.rb:8:in `each'
    from extconf.rb:8:in `find'
    from extconf.rb:8:in `<main>'

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

  /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/puma-3.11.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/puma-3.11.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/puma-3.11.0/gem_make.out

mkmf.log 如下所示:

"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fdebug-prefix-map=/build/ruby2.3-E8maFs/ruby2.3-2.3.3=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC conftest.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.3  -lpthread -lgmp -ldl -lcrypt -lm   -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

更新 1:运行命令dpkg -S libcrypt*

libc6-dev:amd64: /usr/lib/x86_64-linux-gnu/libcrypt.a
libcryptsetup4:amd64: /usr/share/doc/libcryptsetup4
libssl-dev:amd64: /usr/lib/x86_64-linux-gnu/libcrypto.so
libssl-dev:amd64: /usr/lib/x86_64-linux-gnu/libcrypto.a
libcryptsetup4:amd64: /lib/x86_64-linux-gnu/libcryptsetup.so.4.7.0
libcryptsetup4:amd64: /usr/share/doc/libcryptsetup4/copyright
libc6:amd64: /lib/x86_64-linux-gnu/libcrypt-2.26.so
libc6-dev:amd64: /usr/lib/x86_64-linux-gnu/libcrypt.so
libcryptsetup4:amd64: /usr/share/doc/libcryptsetup4/changelog.Debian.gz
libssl-dev:amd64: /usr/lib/x86_64-linux-gnu/pkgconfig/libcrypto.pc
libc6:amd64: /lib/x86_64-linux-gnu/libcrypt.so.1
libcryptsetup4:amd64: /usr/share/doc/libcryptsetup4/NEWS.Debian.gz
libcryptsetup4:amd64: /lib/x86_64-linux-gnu/libcryptsetup.so.4
libssl1.0.0:amd64: /lib/x86_64-linux-gnu/libcrypto.so.1.0.0

更新 2: 的结果ls -l /usr/lib/x86_64-linux-gnu/libcrypt*

-rw-r--r-- 1 root root   60288 1月  12 20:42 /usr/lib/x86_64-linux-gnu/libcrypt.a
lrwxrwxrwx 1 root root      35 1月  12 20:42 /usr/lib/x86_64-linux-gnu/libcrypt.so -> /lib/x86_64-linux-gnu/libcrypt.so.1
-rw-r--r-- 1 root root 4706666 3月  27 18:17 /usr/lib/x86_64-linux-gnu/libcrypto.a
lrwxrwxrwx 1 root root      40 3月  27 18:17 /usr/lib/x86_64-linux-gnu/libcrypto.so -> /lib/x86_64-linux-gnu/libcrypto.so.1.0.0

到底是怎么回事?

注意:我安装了libssl-dev和。libssl1.0-devlibgmp3-dev它们都没有解决问题。

答案1

尝试创建内容如下的 conft.c 文件:

#include <stdio.h>

int main(int argc, char **argv)
{
  return 0;
}

然后在同一目录中获得此文件后,运行以下命令:

gcc -o conft -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2  -fstack-protector-strong -Wformat -Werror=format-security -fPIC conft.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic  -lpthread -lgmp -ldl -lcrypt -lm   -lc

将结果放在这里。如果你只得到“conft”二进制文件,则编译成功完成,我们需要查看“ruby.h”文件。

相关内容