发布于 2016-01-24 23:03:44 | 402 次阅读 | 评论: 1 | 来源: 网友投递

这里有新鲜出炉的Ruby教程,程序狗速度看过来!

Ruby编程语言

Ruby,一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言,在20世纪90年代由日本人松本行弘开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、Ada以及 Lisp 语言。


这篇文章主要介绍了Ruby在cmd下中文显示乱码以及不支持OpenSSL的问题解决,其中OpenSSL的相关编译操作在Linux环境下进行,需要的朋友可以参考下

中文乱码解决办法
cmd下中文不能输入

将cmd代码页改成936:


chcp 936

ruby 读取中文强制设置为utf-8

可以在文件中加一个注释语句 # encoding: UTF-8,ruby就会用utf-8格式载入

cmd输出乱码

这个解决不掉, 我看到有人用了一个第三方库来解决输出 


require 'iconv' 
cov = Iconv.new( 'gbk', 'utf-8')   
puts cov.iconv("北京奥运会!")

PS: Ruby程序中,最好不要出现中文,注释除外

解决ruby不支持openssl的问题
在RHEL 5.4 x86_64安装rails的时候,提示ruby不支持openssl

进入$RUBY_HOME/ext/openssl目录, 执行 ruby exconf.rb,出现如下错误:


=== OpenSSL for Ruby configurator === 
=== Checking for system dependent stuff... === 
checking for t_open() in -lnsl... no 
checking for socket() in -lsocket... no 
checking for assert.h... yes 
=== Checking for required stuff... === 
checking for openssl/ssl.h... no 
=== Checking for required stuff failed. === 

Makefile wasn't created. Fix the errors above.

提示没有找到ssl.h, 从http://www.openssl.org/ 下载了openssl-0.9.8k.tar.gz。 解压,执行configure && make && make install. 回到$RUBY_HOME/ext/openssl重新执行


ruby extconf.rb --with-openssl-include=/usr/local/ssl/include/ --with-openssl-lib=/usr/local/ssl/lib

成功。但接下来执行make时 又出现新的错误:


~/sources/ruby-1.8.7-p174/ext/openssl$ sudo make

gcc -shared -o openssl.so ossl_x509.o ossl_x509cert.o ossl_x509crl.o ossl_pkcs7.o ossl_cipher.o ossl_pkey_dh.o ossl_ssl_session.o ossl_x509attr.o ossl_x509ext.o ossl_ocsp.o ossl_asn1.o ossl_x509name.o ossl_x509revoked.o ossl_rand.o ossl_pkcs12.o ossl_x509store.o ossl_ssl.o ossl.o ossl_digest.o ossl_config.o ossl_pkcs5.o ossl_bio.o ossl_pkey_dsa.o ossl_pkey.o ossl_x509req.o ossl_pkey_ec.o ossl_hmac.o openssl_missing.o ossl_ns_spki.o ossl_pkey_rsa.o ossl_engine.o ossl_bn.o -L. -L/usr/local/ruby/lib -Wl,-R/usr/local/ruby/lib -L/usr/local/ssl/lib -Wl,-R/usr/local/ssl/lib -L. -rdynamic -Wl,-export-dynamic  -lssl -lcrypto -lrt -ldl -lcrypt -lm  -lc

/usr/bin/ld: /usr/local/ssl/lib/libssl.a(s2_meth.o): relocation R_X86_64_32 against `a local symbol'

 can not be used when making a shared object; recompile with -fPIC

/usr/local/ssl/lib/libssl.a: could not read symbols: Bad value

collect2: ld returned 1 exit status

make: *** [openssl.so] Error 1


提示重新试过编译openssl时带上-fPIC参数 。于是重新编译openssl


.confile -fPIC



最新网友评论  共有(1)条评论 发布评论 返回顶部
qgx 发布于2016-03-18 19:59:26
终于搞明白了.
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务