Ruby Ruby 低版本安装 charlock_holmes 问题

mz2test · 2021年02月21日 · 最后由 mz2test 回复于 2021年02月22日 · 174 次阅读

这两天在安装本地环境,使用的是 ruby 2.1.9.在项目中安装 charlock_holmes 依赖,使用 gem 安装成功

$ gem install charlock_holmes -v '0.7.3' -- --with-icu-dir=/usr/local/opt/icu4c@60.2 --with-cxxflags=-std=c++11
Building native extensions with: '--with-icu-dir=/usr/local/opt/icu4c@60.2 --with-cxxflags=-std=c++11'
This could take a while...
Successfully installed charlock_holmes-0.7.3
Parsing documentation for charlock_holmes-0.7.3
Done installing documentation for charlock_holmes after 0 seconds
1 gem installed

但是使用 bundle 安装的时候一直报错

bundle config 配置
build.charlock_holmes
Set for your local app (/Users/jjw/Documents/oschina/gitee-private-code/.bundle/config): "--with-icu-dir=/usr/local/opt/icu4c@60.2 --with-cxxflags=-std=c++11"
Set for the current user (/Users/jjw/.bundle/config): "--with-icu-dir=/usr/local/opt/icu4c@60.2 --with-cxxflags=-std=c++11"

错误:

 current directory: /Users/jjw/Documents/oschina/gitee-private-code/vendor/bundle/ruby/2.1.0/gems/charlock_holmes-0.7.3/ext/charlock_holmes
/Users/jjw/.rvm/rubies/ruby-2.1.9/bin/ruby -I /Users/jjw/.rvm/rubies/ruby-2.1.9/lib/ruby/site_ruby/2.1.0 -r ./siteconf20210221-71958-grpsl3.rb extconf.rb --with-icu-dir\=/usr/local/opt/icu4c@60.2\ --with-cxxflags\=-std\=c\+\+11
checking for main() in -licui18n... no
checking for main() in -licui18n... no


***************************************************************************************
*********** icu required (brew install icu4c or apt-get install libicu-dev) ***********
***************************************************************************************
*** 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
    --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/jjw/.rvm/rubies/ruby-2.1.9/bin/ruby
    --with-icu-dir
    --with-icu-include
    --without-icu-include=${icu-dir}/include
    --with-icu-lib
    --without-icu-lib=${icu-dir}/lib
    --with-icui18nlib
    --without-icui18nlib
    --with-icui18nlib
    --without-icui18nlib

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

  /Users/jjw/Documents/oschina/gitee-private-code/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-19/2.1.0/charlock_holmes-0.7.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/jjw/Documents/oschina/gitee-private-code/vendor/bundle/ruby/2.1.0/gems/charlock_holmes-0.7.3 for inspection.
Results logged to /Users/jjw/Documents/oschina/gitee-private-code/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-19/2.1.0/charlock_holmes-0.7.3/gem_make.out

An error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.7.3' --source 'https://gems.ruby-china.com/'` succeeds before bundling.

In Gemfile:
  github-linguist was resolved to 5.1.0, which depends on
    charlock_holmes

请大家帮忙看看什么问题,感谢!

这是使用 icu4c 67.1,使用$ gem install charlock_holmes -v '0.7.3' -- --with-icu-dir=/usr/local/opt/icu4c --with-cxxflags=-std=c++11 报的错误:

Building native extensions with: '--with-icu-dir=/usr/local/opt/icu4c --with-cxxflags=-std=c++11'
This could take a while...
ERROR:  Error installing charlock_holmes:
    ERROR: Failed to build gem native extension.

    current directory: /Users/jjw/.rvm/gems/ruby-2.1.9/gems/charlock_holmes-0.7.3/ext/charlock_holmes
/Users/jjw/.rvm/rubies/ruby-2.1.9/bin/ruby -I /Users/jjw/.rvm/rubies/ruby-2.1.9/lib/ruby/site_ruby/2.1.0 -r ./siteconf20210221-84999-ya903f.rb extconf.rb --with-icu-dir\=/usr/local/opt/icu4c --with-cxxflags\=-std\=c\+\+11
checking for main() in -licui18n... yes
checking for main() in -licui18n... yes
checking for unicode/ucnv.h... yes
checking for main() in -lz... yes
checking for main() in -licuuc... yes
checking for main() in -licudata... yes
creating Makefile

current directory: /Users/jjw/.rvm/gems/ruby-2.1.9/gems/charlock_holmes-0.7.3/ext/charlock_holmes
make "DESTDIR=" clean

current directory: /Users/jjw/.rvm/gems/ruby-2.1.9/gems/charlock_holmes-0.7.3/ext/charlock_holmes
make "DESTDIR="
compiling ext.c
In file included from ext.c:1:
./common.h:14:14: warning: unused function 'charlock_new_enc_str' [-Wunused-function]
static VALUE charlock_new_enc_str(const char *str, size_t len, void *encoding)
             ^
./common.h:23:14: warning: unused function 'charlock_new_str' [-Wunused-function]
static VALUE charlock_new_str(const char *str, size_t len)
             ^
./common.h:32:14: warning: unused function 'charlock_new_str2' [-Wunused-function]
static VALUE charlock_new_str2(const char *str)
             ^
3 warnings generated.
compiling encoding_detector.c
encoding_detector.c:166:71: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
                ucsdet_setDeclaredEncoding(detector->csd, RSTRING_PTR(rb_enc_hint), RSTRING_LEN(rb_enc_hint), &status);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~                                          ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:843:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:839:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
encoding_detector.c:166:71: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
                ucsdet_setDeclaredEncoding(detector->csd, RSTRING_PTR(rb_enc_hint), RSTRING_LEN(rb_enc_hint), &status);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~                                          ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:844:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
encoding_detector.c:215:71: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
                ucsdet_setDeclaredEncoding(detector->csd, RSTRING_PTR(rb_enc_hint), RSTRING_LEN(rb_enc_hint), &status);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~                                          ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:843:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:839:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
encoding_detector.c:215:71: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
                ucsdet_setDeclaredEncoding(detector->csd, RSTRING_PTR(rb_enc_hint), RSTRING_LEN(rb_enc_hint), &status);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~                                          ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:844:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from encoding_detector.c:2:
./common.h:14:14: warning: unused function 'charlock_new_enc_str' [-Wunused-function]
static VALUE charlock_new_enc_str(const char *str, size_t len, void *encoding)
             ^
5 warnings generated.
compiling converter.c
converter.c:23:12: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        src_len = RSTRING_LEN(rb_txt);
                ~ ^~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:843:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:839:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
converter.c:23:12: warning: implicit conversion loses integer precision: 'long' to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
        src_len = RSTRING_LEN(rb_txt);
                ~ ^~~~~~~~~~~~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:844:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from converter.c:2:
./common.h:23:14: warning: unused function 'charlock_new_str' [-Wunused-function]
static VALUE charlock_new_str(const char *str, size_t len)
             ^
./common.h:32:14: warning: unused function 'charlock_new_str2' [-Wunused-function]
static VALUE charlock_new_str2(const char *str)
             ^
4 warnings generated.
compiling transliterator.cpp
In file included from transliterator.cpp:1:
In file included from ./common.h:9:
In file included from /Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby.h:33:
In file included from /Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/ruby.h:1702:
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/intern.h:47:19: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
                  ^~~~~~~~~
/Users/jjw/.rvm/rubies/ruby-2.1.9/include/ruby-2.1.0/ruby/intern.h:47:36: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
                                   ^~~~~~~~~
transliterator.cpp:39:3: error: unknown type name 'StringEnumeration'; did you mean 'icu_67::StringEnumeration'?
  StringEnumeration *id_list;
  ^~~~~~~~~~~~~~~~~
  icu_67::StringEnumeration
/usr/local/opt/icu4c/include/unicode/strenum.h:61:20: note: 'icu_67::StringEnumeration' declared here
class U_COMMON_API StringEnumeration : public UObject {
                   ^
transliterator.cpp:47:13: error: use of undeclared identifier 'Transliterator'; did you mean 'icu_67::Transliterator'?
  id_list = Transliterator::getAvailableIDs(status);
            ^~~~~~~~~~~~~~
            icu_67::Transliterator
/usr/local/opt/icu4c/include/unicode/translit.h:490:18: note: 'icu_67::Transliterator' declared here
class U_I18N_API Transliterator : public UObject {
                 ^
transliterator.cpp:81:3: error: unknown type name 'Transliterator'; did you mean 'UTransliterator'?
  Transliterator *trans;
  ^~~~~~~~~~~~~~
  UTransliterator
/usr/local/opt/icu4c/include/unicode/utrans.h:70:15: note: 'UTransliterator' declared here
typedef void* UTransliterator;
              ^
transliterator.cpp:86:3: error: unknown type name 'UnicodeString'; did you mean 'icu_67::UnicodeString'?
  UnicodeString *u_txt;
  ^~~~~~~~~~~~~
  icu_67::UnicodeString
/usr/local/opt/icu4c/include/unicode/unistr.h:294:20: note: 'icu_67::UnicodeString' declared here
class U_COMMON_API UnicodeString : public Replaceable
                   ^
transliterator.cpp:101:11: error: use of undeclared identifier 'Transliterator'; did you mean 'icu_67::Transliterator'?
  trans = Transliterator::createInstance(UnicodeString(id, id_len), UTRANS_FORWARD, p_error, status);
          ^~~~~~~~~~~~~~
          icu_67::Transliterator
/usr/local/opt/icu4c/include/unicode/translit.h:490:18: note: 'icu_67::Transliterator' declared here
class U_I18N_API Transliterator : public UObject {
                 ^
transliterator.cpp:101:42: error: use of undeclared identifier 'UnicodeString'; did you mean 'icu_67::UnicodeString'?
  trans = Transliterator::createInstance(UnicodeString(id, id_len), UTRANS_FORWARD, p_error, status);
                                         ^
/usr/local/opt/icu4c/include/unicode/unistr.h:294:20: note: 'icu_67::UnicodeString' declared here
class U_COMMON_API UnicodeString : public Replaceable
                   ^
transliterator.cpp:106:15: error: unknown type name 'UnicodeString'; did you mean 'icu_67::UnicodeString'?
  u_txt = new UnicodeString(txt, txt_len);
              ^~~~~~~~~~~~~
              icu_67::UnicodeString
/usr/local/opt/icu4c/include/unicode/unistr.h:294:20: note: 'icu_67::UnicodeString' declared here
class U_COMMON_API UnicodeString : public Replaceable
                   ^
transliterator.cpp:107:8: error: member reference base type 'UTransliterator' (aka 'void *') is not a structure or union
  trans->transliterate(*u_txt);
  ~~~~~^ ~~~~~~~~~~~~~
transliterator.cpp:108:30: error: expected ';' after expression
  StringByteSink<std::string> sink(&result);
                             ^
                             ;
transliterator.cpp:108:3: error: use of undeclared identifier 'StringByteSink'
  StringByteSink<std::string> sink(&result);
  ^
transliterator.cpp:108:31: error: use of undeclared identifier 'sink'
  StringByteSink<std::string> sink(&result);
                              ^
transliterator.cpp:109:17: error: use of undeclared identifier 'sink'
  u_txt->toUTF8(sink);
                ^
2 warnings and 12 errors generated.
make: *** [transliterator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/jjw/.rvm/gems/ruby-2.1.9/gems/charlock_holmes-0.7.3 for inspection.
Results logged to /Users/jjw/.rvm/gems/ruby-2.1.9/extensions/x86_64-darwin-19/2.1.0/charlock_holmes-0.7.3/gem_make.out
***************************************************************************************
*********** icu required (brew install icu4c or apt-get install libicu-dev) ***********
***************************************************************************************
*** extconf.rb failed ***

看这个提示, 要安装 libicu 的开发包

sevk 回复

指定了 icu 目录了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号