Ruby在cmd下中文顯示亂碼以及不支援OpenSSL的問題解決_ruby專題

來源:互聯網
上載者:User

中文亂碼解決辦法
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 makegcc -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 valuecollect2: ld returned 1 exit statusmake: *** [openssl.so] Error 1


提示重新試過編譯openssl時帶上-fPIC參數 。於是重新編譯openssl

.confile -fPIC

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.