论坛首页 编程语言技术论坛

Rails项目安装Swiftiply时出现编译错误问题的解决办法

浏览 2202 次
精华帖 (1) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-04-02   最后修改:2009-04-02
    最近在用Rails做一个网站,本来选用了Nginx+Mongrel的部署方式,也试了Nginx+Thin,后来看到JavaEye上一篇文章浅析Ruby on Rails部署方案,其中介绍了Swiftiply有很好的性能,因此,准备用Swiftiply来部署项目。

    看了Swiftiply官网http://swiftiply.swiftcore.org的安装步骤,直接用gem安装:
$ sudo gem install swiftiply

    安装过程中先后自动装上了rack和EventMachine,最后编译Swiftiply时出错:
引用
Building native extensions.  This could take a while...
ERROR:  Error installing swiftiply:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install swiftiply
checking for main() in -lpthread... yes
checking for sys/epoll.h... yes
checking for main() in -lssl... no
creating Makefile

make
g++ -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I. -DHAVE_SYS_EPOLL_H  -D_FILE_OFFSET_BITS=64  -DOS_UNIX -DBUILD_FOR_RUBY -DHAVE_EPOLL -DWITHOUT_SSL -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c rubymain.cpp
g++ -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I. -DHAVE_SYS_EPOLL_H  -D_FILE_OFFSET_BITS=64  -DOS_UNIX -DBUILD_FOR_RUBY -DHAVE_EPOLL -DWITHOUT_SSL -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c mapper.cpp
mapper.cpp: In constructor ‘Mapper_t::Mapper_t(const std::string&)’:
mapper.cpp:53: error: ‘strerror’ was not declared in this scope
mapper.cpp:57: error: ‘strerror’ was not declared in this scope
mapper.cpp:62: error: ‘strerror’ was not declared in this scope
make: *** [mapper.o] Error 1


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/swiftiply-0.6.1.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/swiftiply-0.6.1.1/ext/fastfilereader/gem_make.out

  
    我痕郁闷啊!!!排错吧。
    首先,在google搜索一下:发现有一两个帖子也是这个问题,但是都没有答案。只好自己找了。
    第一步我怀疑是我的开发环境没装好,我用的是Ubuntu Server 8.10,检查了一下,开发包都装上了,别的软件也都能编译,包括mongrel。
    第二步怀疑是编译器的问题,gcc或g++,搜了一下,gcc4.3好像有类似问题,有补丁,我这是gcc4.4.3,没找到。
    只好仔细看程序了,不偷懒了,看出错信息应该是缺少头文件的问题,在/usr/lib/ruby/gems/1.8/gems/swiftiply-0.6.1.1/ext/fastfilereader/下找到mapper.cpp文件,打开看了一下,头文件好像缺少。刚好,在搜文件的时候在/usr/lib/ruby/gems/1.8/gems/eventmachine-0.12.6/ext/fastfilereader/下也有这个文件,用diff比较一下:
$diff mapper.cpp ../../../eventmachine-0.12.6/ext/fastfilereader/mapper.cpp

引用
34a35
> #include "unistd.h"
35a37
> #include <cstring>
59a62,64
>       #ifdef OS_WIN32
>       MapPoint = (char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
>       #else
60a66
>       #endif
84a91,93

>               #ifdef OS_SOLARIS8
>               munmap ((char*)MapPoint, FileSize);
>               #else
85a95
>               #endif
150a161,163
>       #ifdef OS_WIN32
>       MapPoint = (char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
>       #else
151a165
>       #endif

    输出表明,缺少了两个头文件声明:
引用
#include "unistd.h"
#include <cstring>

    用vi修改mapper.cpp文件,加上这两行。
     然后,运行swiftiply的安装程序:
$ sudo ruby setup.rb

引用
Building extension in /home/tian/swiftiply-0.6.1.1/ext/fastfilereader with {:mkmf=>true}.
checking for main() in -lpthread... yes
checking for sys/epoll.h... yes
checking for main() in -lssl... no
creating Makefile
g++ -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I/home/tian/swiftiply-0.6.1.1/ext/fastfilereader -DHAVE_SYS_EPOLL_H  -D_FILE_OFFSET_BITS=64  -DOS_UNIX -DBUILD_FOR_RUBY -DHAVE_EPOLL -DWITHOUT_SSL -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c rubymain.cpp
g++ -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I/home/tian/swiftiply-0.6.1.1/ext/fastfilereader -DHAVE_SYS_EPOLL_H  -D_FILE_OFFSET_BITS=64  -DOS_UNIX -DBUILD_FOR_RUBY -DHAVE_EPOLL -DWITHOUT_SSL -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c mapper.cpp
g++ -shared -o fastfilereaderext.so rubymain.o mapper.o -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic    -lruby1.8 -lpthread  -lpthread -ldl -lcrypt -lm   -lc; strip fastfilereaderext.so
Installing Swiftcore Swiftiply ...
mkdir -p /usr/bin
install -c -m 0755 bin/mongrel_rails /usr/bin/mongrel_rails
install -c -m 0755 bin/swiftiply /usr/bin/swiftiply
install -c -m 0755 bin/swiftiply_mongrel_rails /usr/bin/swiftiply_mongrel_rails
mkdir -p /usr/local/lib/site_ruby/1.8/i486-linux
install -c -m 0755 ext/fastfilereader/fastfilereaderext.so /usr/local/lib/site_ruby/1.8/i486-linux/fastfilereaderext.so
mkdir -p /usr/local/lib/site_ruby/1.8/swiftcore
install -c -m 0644 src/swiftcore/Swiftiply.rb /usr/local/lib/site_ruby/1.8/swiftcore/Swiftiply.rb
mkdir -p /usr/local/lib/site_ruby/1.8/swiftcore/Swiftiply
install -c -m 0644 src/swiftcore/Swiftiply/support_pagecache.rb /usr/local/lib/site_ruby/1.8/swiftcore/Swiftiply/support_pagecache.rb
install -c -m 0644 src/swiftcore/Swiftiply/swiftiply_client.rb /usr/local/lib/site_ruby/1.8/swiftcore/Swiftiply/swiftiply_client.rb
install -c -m 0644 src/swiftcore/evented_mongrel.rb /usr/local/lib/site_ruby/1.8/swiftcore/evented_mongrel.rb
install -c -m 0644 src/swiftcore/swiftiplied_mongrel.rb /usr/local/lib/site_ruby/1.8/swiftcore/swiftiplied_mongrel.rb
install -c -m 0644 src/swiftcore/types.rb /usr/local/lib/site_ruby/1.8/swiftcore/types.rb
shebang:open /usr/bin/mongrel_rails.tmp
rm -f /usr/bin/mongrel_rails.tmp
shebang:open /usr/bin/swiftiply.tmp
mv /usr/bin/swiftiply.tmp /usr/bin/swiftiply
rm -f /usr/bin/swiftiply.tmp
shebang:open /usr/bin/swiftiply_mongrel_rails.tmp
rm -f /usr/bin/swiftiply_mongrel_rails.tmp
Generating ri documentation from src/swiftcore/Swiftiply.rb,src/swiftcore/evented_mongrel.rb,src/swiftcore/Swiftiply/swiftiply_client.rb,src/swiftcore/Swiftiply/support_pagecache.rb,src/swiftcore/swiftiplied_mongrel.rb,src/swiftcore/types.rb

                       Swiftiply.rb: mmccc..............................c.......c...........
                 evented_mongrel.rb: mc....c....c.c.....c.
                swiftiply_client.rb: c.......
               support_pagecache.rb: mmcc.....
             swiftiplied_mongrel.rb: mc....c....c.c....c.
                           types.rb: mcc...........c................c.........c........
Generating RI...

Files:   6
Classes: 23
Modules: 7
Methods: 133
Elapsed: 3.445s


    OK!编译通过!
    后面的Swiftiply配置和运行都比较顺利,应用跑起来之后,性能比Nginx+Mongrel确实有提高,尤其是大的并发出现时,性能比较稳定。
    总结:在Linux下安装程序,出现编译问题是常有的事,要解决问题,终极的办法还是看源代码。
    不过提到Swiftiply,好像用的人不多啊,像这样的编译问题,肯定会遇到,却搜不到解决方案,稍显遗憾。

运行环境:
引用

    Ubuntu Server 8.10
    ruby 1.8.7
    rails 2.3.2
    Swiftiply 0.6.1.1
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics