运行捆绑安装时出现 C 标头问题

问题描述 投票:0回答:1

我正在尝试运行 ruby 应用程序,因此我首先尝试运行

bundle install
来安装所有必需的 gem。对于不同的宝石,我不断遇到以下错误。我已经在 StackOverflow 上尝试了多种解决方案,但似乎没有任何帮助。我安装了 XCode 开发人员工具(通过
xcode-select --install
)并且正在运行 Mac OS Ventura 13.6 (22G120)

Installing prometheus-client 4.2.2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/xyz/.rvm/gems/ruby-3.2.2/gems/prism-0.15.1/ext/prism
/Users/xyz/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb
checking for whether -fvisibility=hidden is accepted as CFLAGS... yes
compiling build/static/diagnostic.o
In file included from src/diagnostic.c:1:
In file included from include/prism/diagnostic.h:4:
include/prism/defines.h:6:10: fatal error: 'ctype.h' file not found
#include <ctype.h>
         ^~~~~~~~~
1 error generated.
make: *** [build/static/diagnostic.o] Error 1
*** 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/xyz/.rvm/rubies/ruby-3.2.2/bin/$(RUBY_BASE_NAME)
    --enable-debug-mode-build
    --disable-debug-mode-build
    --enable-static
    --disable-static
extconf.rb:78:in `system': Command failed with exit 2: make (RuntimeError)
    from extconf.rb:78:in `block in build_target_rubyparser'
    from extconf.rb:72:in `chdir'
    from extconf.rb:72:in `build_target_rubyparser'
    from extconf.rb:68:in `build_static_rubyparser'
    from extconf.rb:42:in `configure_rubyparser'
    from extconf.rb:20:in `configure'
    from extconf.rb:136:in `<main>'

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

  /Users/xyz/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-22/3.2.0/prism-0.15.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/xyz/.rvm/gems/ruby-3.2.2/gems/prism-0.15.1 for inspection.
Results logged to /Users/xyz/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-22/3.2.0/prism-0.15.1/gem_make.out

  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:120:in `run'
  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:188:in `build_extension'
  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:222:in `block in build_extensions'
  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:219:in `each'
  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:219:in `build_extensions'
  /Users/xyz/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/installer.rb:844:in `build_extensions'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/source/rubygems.rb:202:in `install'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/installer/parallel_installer.rb:156:in `do_install'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/installer/parallel_installer.rb:147:in `block in worker_pool'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/worker.rb:62:in `apply_func'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/worker.rb:54:in `loop'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/worker.rb:54:in `process_queue'
  /Users/xyz/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.18/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing prism (0.15.1), and Bundler cannot continue.

In Gemfile:
  tapioca was resolved to 0.11.9, which depends on
    rbi was resolved to 0.1.2, which depends on
      prism

当我猫

mkmf.log
时,我得到以下输出:

cat /Users/xyz/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-22/3.2.0/prism-0.15.1/mkmf.log


block in append_cflags: checking for whether -fvisibility=hidden is accepted as CFLAGS... -------------------- yes

DYLD_FALLBACK_LIBRARY_PATH=.:/Users/xyz/.rvm/rubies/ruby-3.2.2/lib "gcc -o conftest -I/Users/xyz/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/arm64-darwin22 -I/Users/xyz/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/ruby/backward -I/Users/xyz/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/[email protected]/include -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wundef -fno-common -pipe conftest.c  -L. -L/Users/xyz/.rvm/rubies/ruby-3.2.2/lib -L. -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/[email protected]/lib -fstack-protector-strong     -lruby.3.2  -lpthread  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

DYLD_FALLBACK_LIBRARY_PATH=.:/Users/xyz/.rvm/rubies/ruby-3.2.2/lib "gcc -I/Users/xyz/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/arm64-darwin22 -I/Users/xyz/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/ruby/backward -I/Users/xyz/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/[email protected]/include -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wundef -fno-common -pipe  -fvisibility=hidden -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

--------------------
ruby-on-rails ruby xcode bundler
1个回答
0
投票

连续几天谷歌搜索后,我通过两个步骤解决了这个问题:

  1. 使用以下命令卸载并重新安装 XCode 开发工具
   sudo rm -rf $(xcode-select -p)
   xcode-select --install
  1. 使用以下命令手动设置 SDKROOT 环境变量以指向正确的位置:
   export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)

这对我有用。它应该可以让外面的人免于头痛。

© www.soinside.com 2019 - 2024. All rights reserved.