无法构建gem原生扩展

无法构建gem原生扩展

本文介绍了无法构建gem原生扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最终结果是我试图在我的操作系统10.7.3上安装Ruby on Rails,但遇到各种问题。



另外,我有一个新安装的XCode 4.3来自App Store。



当我启动终端时,输入:

  sudo gem install rails 

并且写出:

 构建原生扩展。这可能需要一段时间... 
错误:安装rails出错:
错误:无法构建gem本机扩展。

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb无法找到ruby的头文件在/ System / Library / Frameworks / Ruby.framework / Versions / 1.8 / usr / lib / ruby​​ / ruby​​.h


Gem文件将保留在/Library/Ruby/Gems/1.8/gems/中json-1.6.5进行检查。
结果记录到/Library/Ruby/Gems/1.8/gems/json-1.6.5/ext/json/ext/parser/gem_make.out

在我找到的所有修复中,都说安装了XCode,而且它运行得很好。但是,我没有卸载以前版本的XCode来安装最新版本,所以我想知道是否有任何关系。

编辑1:
我遵循Jasdeep建议并安装了RVM。但是,一旦我运行:

  sudo rvm install 1.9.3 

我得到以下结果:

 获取yaml-0.1.4。 tar.gz到/Users/xxx/.rvm/archives 
将yaml-0.1.4.tar.gz提取到/Users/xxx/.rvm/src
在/ Users / xxx /中配置yaml。 RVM / SRC / YAML-0.1.4。
运行'./configure --prefix =/ Users / xxx / .rvm / usr'错误,请阅读/Users/xxx/.rvm/log/ruby-1.9.3-p0/yaml/configure .log
在/Users/xxx/.rvm/src/yaml-0.1.4中编译yaml。
运行'make'时出错,请阅读/Users/xxx/.rvm/log/ruby-1.9.3-p0/yaml/make.log


数据库文件/用户/ xxx / .rvm / config / packages不存在。

gcc-4.2:尝试执行错误'/usr/bin/i686-apple-darwin11-gcc-4.2.1':execvp:没有这样的文件或目录
从源代码安装Ruby到:/Users/xxx/.rvm/rubies/ruby-1.9.3-p0,这可能需要一段时间取决于你的cpu(s)...

ruby​​-1.9.3-p0 - #fetching
ruby​​-1.9.3-p0 - #下载ruby-1.9.3-p0,这可能需要一段时间,具体取决于您的连接...
%总计%收到%Xferd平均速度时间时间时间当前
上传总花费左转速度
100 9330k 100 9330k 0 0 645k 0 0:00:14 0:00:14 - : - : - 1260k
ruby​​- 1.9.3-p0 - #extracting ruby​​-1.9.3-p0到/Users/xxx/.rvm/src/ruby-1.9.3-p0
ruby​​-1.9.3-p0 - #extracted to / Users /xxx/.rvm/src/ruby-1.9.3-p0
ruby​​-1.9.3-p0 - #configuring
运行'./configure --prefix = / Users / xxx / .rvm /rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir = / Users / xxx / .rvm / usr',请阅读/Users/xxx/.rvm/log/ruby-1.9.3-p0/configure.log
运行configure时出错。停止安装。

然后我查找了日志文件中的内容,..ruby-1.9.3-p0 /yaml/configure.log:

  [2012-03-03 22:49:50] ./configure --prefix = /Users/xxx/.rvm/usr
检查BSD兼容安装... / usr / bin / install -c
检查构建环境是否理智...是
检查线程安全的mkdir -p ... config / install-sh -c -d
检查gawk ... no
检查mawk ... no
检查nawk ... no
检查awk ... awk
检查make sets $(MAKE)... no
检查gcc ... no
检查cc ... no
检查cl.exe ... no
configure:error:in`/Users/xxx/.rvm/src/yaml-0.1.4':
configure:错误:在$ PATH中找不到可接受的C编译器
查看`config.log'以获取更多详细信息




pre $ 没有可接受的C编译器在$ PATH中找到

编辑2:



我遵循了matt的指示,并且一旦我安装了命令行工具(因为我现在有Xcode 4.3)就能够进一步获得更多信息。然而,我仍然收到一个错误:

 取得yaml-0.1.4.tar.gz到/ Users / xxx / .rvm / archives 
将yaml-0.1.4.tar.gz提取到/Users/xxx/.rvm/src
在/Users/xxx/.rvm/src/yaml-0.1.4中配置yaml 。
在/Users/xxx/.rvm/src/yaml-0.1.4中编译yaml。
将yaml安装到/Users/xxx/.rvm/usr
gcc-4.2:尝试执行'/usr/bin/i686-apple-darwin11-gcc-4.2.1'时出错:execvp:No这样的文件或目录
将Ruby从源代码安装到:/Users/xxx/.rvm/rubies/ruby-1.9.3-p0,这可能需要一段时间,具体取决于您的cpu(s)...

ruby​​-1.9.3-p0 - #fetching
ruby​​-1.9.3-p0 - #提取到/Users/xxx/.rvm/src/ruby-1.9.3-p0(已提取)
ruby​​-1.9.3-p0 - #configuring
运行'./configure --prefix = / Users / xxx / .rvm / rubies / ruby​​-1.9.3-p0 --enable- shared --disable-install-doc --with-libyaml --with-opt-dir = / Users / xxx / .rvm / usr',请阅读/Users/xxx/.rvm/log/ruby-1.9.3- p0 / configure.log
运行configure时出错。停止安装。

下面是configure.log(对不起,这篇文章太长了,但希望它可以帮助其他人:

  [2012-03-04 09:29:35] ./configure --prefix =/ Users / xxx / .rvm / usr
检查BSD兼容安装... / usr / bin / install -c
检查构建环境是否健全...是
检查线程安全的mkdir -p ... config / install-sh -c -d
检查gawk ...没有
检查mawk ...没有
检查nawk ... no
检查awk ... awk
检查是否make sets $(MAKE)...是
检查gcc ... gcc
检查C编译器是否工作。 ..是
检查C编译器的默认输出文件名... a.out
检查可执行文件的后缀...
检查我们是否正在交叉编译... no
检查目标文件的后缀... o
检查我们是否使用GNU C编译器...是
检查gcc是否接受-g ...是
检查gcc选项接受ISO C89 ...无需
检查make所使用的包含样式... GNU
检查gcc的依赖样式... gcc3
检查如何运行C预处理器。 .. gcc -E
检查ln -s是否工作...是
检查是否make sets $(MAKE)...(缓存)是
检查编译系统类型... x86_64 -apple-darwin11.3.0
检查主机系统类型... x86_64-apple-darwin11.3.0
检查不截断输出的sed ... / usr / bin / sed
检查处理长行的grep和-e ... / usr / bin / grep
检查egrep ... / usr / bin / grep -E
检查fgrep ... / usr / bin / grep -F
检查gcc使用的ld ... /usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld
检查链接器(/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld)是GNU ld ... no
检查BSD或MS兼容名称lister(nm) ... / usr / bin / nm
检查名称列表器(/ usr / bin / nm)接口... BSD nm
检查最大值ngth命令行参数... 196608
检查shell是否理解一些XSI结构...是
检查shell是否理解+ =...是
检查/ usr /llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld选项重新加载对象文件... -r
检查objdump ... no
检查如何识别相关库... pass_all
检查ar ... ar
检查strip ... strip
检查ranlib ... ranlib
检查命令以解析/ usr / bin / nm输出来自gcc对象... ok
检查dsymutil ... dsymutil
检查nmedit ... nmedit
检查lipo ... lipo
检查for otool ... otool
检查otool64 ... no
检查-single_module链接器标志...是
检查-exported_symbols_list链接器标志...是
检查对于ANSI C头文件...是
检查sys / types.h ...是
检查sys / stat.h ...是
检查stdlib.h ..是
检查是否符合条件gh ..是
检查memory.h ...是
检查strings.h ...是
检查inttypes.h ...是
检查stdint .h ...是
检查unistd.h ...是
检查dlfcn.h ...是
检查objdir ... .libs
检查是否gcc支持-fno-rtti -fno-exceptions ... no
检查gcc选项以产生PIC ... -fno-common -DPIC
检查gcc PIC标志-fno-common -DPIC是否工作...是
检查gcc静态标志-static是否工作...否
检查gcc是否支持-c -o file.o ...是
检查gcc是否支持-c - o file.o ...(缓存)是
检查gcc链接器(/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld)是否支持共享库。 ..是
检查动态链接器特性... darwin11.3.0 dyld
检查如何将库路径硬编码为程序... immediate
检查是否可以删除库... yes
检查libtool是否支持共享库...是
checkin g是否构建共享库...是
检查是否构建静态库...是
检查doxygen ... false
检查ANSI C头文件...(缓存)是
检查stdlib.h ...(缓存)是
检查符合ANSI C的常量...是
检查size_t ...是
配置:创建./config.status
config.status:创建yaml-0.1.pc
config.status:创建include / Makefile
config.status:创建src / Makefile
config .status:创建Makefile
config.status:创建测试/ Makefile
config.status:创建win32 / Makefile
config.status:创建config.h
config.status:config .h不变
config.status:执行depfiles命令
config.status:执行libtool命令


问题是,在Lion Xcode 4.3中不会默认安装(甚至包括)gcc等命令行工具 - 而这些都是ne在这里结束。在Xcode首选项的下载窗格中,在组件下,请求命令行工具。 (请参阅自述文件: )实际上我相信你根本不需要安装Xcode,因为实际上命令行工具现在可以单独下载和安装。


End result is I'm trying to get Ruby on Rails installed on my OS 10.7.3, but having various issues.

Also, I have a freshly installed XCode 4.3 from the App Store.

When I fire up the terminal, and enter:

sudo gem install rails

and it writes out:

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

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/json-1.6.5 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.6.5/ext/json/ext/parser/gem_make.out

In all of the fixes I'm finding says to install XCode, which I have and runs just fine. However, I did uninstall a previous version of XCode to install the latest version, so I'm wondering if there is any relation there.

EDIT 1:I've followed Jasdeep suggestion and installed RVM. But once i run:

sudo rvm install 1.9.3

I get the following:

Fetching yaml-0.1.4.tar.gz to /Users/xxx/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/xxx/.rvm/src
Configuring yaml in /Users/xxx/.rvm/src/yaml-0.1.4.
Error running ' ./configure --prefix="/Users/xxx/.rvm/usr"  ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/yaml/configure.log
Compiling yaml in /Users/xxx/.rvm/src/yaml-0.1.4.
Error running 'make ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/yaml/make.log


Database file /Users/xxx/.rvm/config/packages does not exist.

gcc-4.2: error trying to exec '/usr/bin/i686-apple-darwin11-gcc-4.2.1': execvp: No such file or directory
Installing Ruby from source to: /Users/xxx/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...

ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9330k  100 9330k    0     0   645k      0  0:00:14  0:00:14 --:--:-- 1260k
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /Users/xxx/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #extracted to /Users/xxx/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #configuring
Error running ' ./configure --prefix=/Users/xxx/.rvm/rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir=/Users/xxx/.rvm/usr ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/configure.log
There has been an error while running configure. Halting the installation.

So then I looked up what was in the log file, ..ruby-1.9.3-p0/yaml/configure.log:

[2012-03-03 22:49:50]  ./configure --prefix="/Users/xxx/.rvm/usr"
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... config/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/Users/xxx/.rvm/src/yaml-0.1.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

So now it appears the error is:

no acceptable C compiler found in $PATH

Edit 2:

I've followed matt's instructions and was able to get further once I got the command-line tools installed (since I have Xcode 4.3 now). However, I'm still getting an error:

Fetching yaml-0.1.4.tar.gz to /Users/xxx/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/xxx/.rvm/src
Configuring yaml in /Users/xxx/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/xxx/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/xxx/.rvm/usr
gcc-4.2: error trying to exec '/usr/bin/i686-apple-darwin11-gcc-4.2.1': execvp: No such file or directory
Installing Ruby from source to: /Users/xxx/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...

ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #extracted to /Users/xxx/.rvm/src/ruby-1.9.3-p0 (already extracted)
ruby-1.9.3-p0 - #configuring
Error running ' ./configure --prefix=/Users/xxx/.rvm/rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir=/Users/xxx/.rvm/usr ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/configure.log
There has been an error while running configure. Halting the installation.

Below is the configure.log (sorry this post is getting so long, but hopefully it can help others too):

[2012-03-04 09:29:35]  ./configure --prefix="/Users/xxx/.rvm/usr"
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... config/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking whether ln -s works... yes
checking whether make sets $(MAKE)... (cached) yes
checking build system type... x86_64-apple-darwin11.3.0
checking host system type... x86_64-apple-darwin11.3.0
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld
checking if the linker (/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm
checking the name lister (/usr/bin/nm) interface... BSD nm
checking the maximum length of command line arguments... 196608
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm output from gcc object... ok
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin11.3.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for doxygen... false
checking for ANSI C header files... (cached) yes
checking for stdlib.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
configure: creating ./config.status
config.status: creating yaml-0.1.pc
config.status: creating include/Makefile
config.status: creating src/Makefile
config.status: creating Makefile
config.status: creating tests/Makefile
config.status: creating win32/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
解决方案

The problem is that in Lion Xcode 4.3 doesn't by default install (or even include) the command-line tools such as gcc - and those are what are needed here. In the Downloads pane of Xcode's prefs, under Components, ask for the command-line tools. (See the readme: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Chapters/xcode_4_0.html#//apple_ref/doc/uid/TP40016147-SW35)

Actually I believe you didn't need to install Xcode at all, since in fact the command-line tool can now be downloaded and installed separately.

这篇关于无法构建gem原生扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 12:05