charlock_holmes: Unable to install version 0.7.3 on Mac OS Sierra

Ruby 2.4.1 Mac OS Version 10.12.6

$> gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.11
  - RUBY VERSION: 2.4.1 (2017-03-22 patchlevel 111) [x86_64-darwin16]
  - INSTALLATION DIRECTORY: /Users/agargiulo/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
  - USER INSTALLATION DIRECTORY: /Users/agargiulo/.gem/ruby/2.4.0
  - RUBY EXECUTABLE: /Users/agargiulo/.rbenv/versions/2.4.1/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/agargiulo/.rbenv/versions/2.4.1/bin
  - SPEC CACHE DIRECTORY: /Users/agargiulo/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/agargiulo/.rbenv/versions/2.4.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-16
  - GEM PATHS:
     - /Users/agargiulo/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
     - /Users/agargiulo/.gem/ruby/2.4.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/agargiulo/.rbenv/versions/2.4.1/bin
     - /usr/local/Cellar/rbenv/1.1.1/libexec
     - /Users/agargiulo/.rbenv/shims
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Applications/Wireshark.app/Contents/MacOS
     - /Users/agargiulo/bin
     - /Users/agargiulo/.rbenv/shims

Output from bundle install

Installing charlock_holmes 0.7.3 with native extensions                                                                                                                                           [103/1714]
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/agargiulo/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/charlock_holmes-0.7.3/ext/charlock_holmes
/Users/agargiulo/.rbenv/versions/2.4.1/bin/ruby -r ./siteconf20170813-46115-56zgwh.rb extconf.rb
checking for -licui18n... no
checking for -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
        --without-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/agargiulo/.rbenv/versions/2.4.1/bin/$(RUBY_BASE_NAME)
        --with-icu-dir
        --without-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/agargiulo/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/charlock_holmes-0.7.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/agargiulo/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/charlock_holmes-0.7.3 for inspection.
Results logged to /Users/agargiulo/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/charlock_holmes-0.7.3/gem_make.out

An error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue.

Contents of that mkmf.log file

have_library: checking for -licui18n... -------------------- no

"clang -o conftest -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0/x86_64-darwin16 -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0/ruby/backward -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0 -I. -I/Users/agargiulo/.rbenv/versions/2.4.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/agargiulo/.rbenv/versions/2.4.1/lib -L. -L/Users/agargiulo/.rbenv/versions/2.4.1/lib  -fstack-protector -L/usr/local/lib     -lruby-static -framework CoreFoundation  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"clang -o conftest -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0/x86_64-darwin16 -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0/ruby/backward -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0 -I. -I/Users/agargiulo/.rbenv/versions/2.4.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/agargiulo/.rbenv/versions/2.4.1/lib -L. -L/Users/agargiulo/.rbenv/versions/2.4.1/lib  -fstack-protector -L/usr/local/lib     -lruby-static -framework CoreFoundation -licui18n  -lpthread -ldl -lobjc "
ld: library not found for -licui18n
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     printf("%p", &t);
 9:   }
10: 
11:   return 0;
12: }
13: 
14: int t(void) { ; return 0; }
/* end */

--------------------

have_library: checking for -licui18n... -------------------- no

"clang -o conftest -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0/x86_64-darwin16 -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0/ruby/backward -I/Users/agargiulo/.rbenv/versions/2.4.1/include/ruby-2.4.0 -I. -I/Users/agargiulo/.rbenv/versions/2.4.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/agargiulo/.rbenv/versions/2.4.1/lib -L. -L/Users/agargiulo/.rbenv/versions/2.4.1/lib  -fstack-protector -L/usr/local/lib     -lruby-static -framework CoreFoundation -licui18n  -lpthread -ldl -lobjc "
ld: library not found for -licui18n
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     printf("%p", &t);
 9:   }
10: 
11:   return 0;
12: }
13: 
14: int t(void) { ; return 0; }
/* end */

--------------------

About this issue

Most upvoted comments

I had to do this:

gem install charlock_holmes -v '0.7.3' -- --with-cppflags=-DU_USING_ICU_NAMESPACE=1 --with-cxxflags=-std=c++11

Got the same problem when trying to install 0.7.5 using ruby 2.4.1, Sierra 10.12.6, icu4c 59.1

In file included from transliterator.cpp:5:
In file included from /usr/local/Cellar/icu4c/59.1/include/unicode/translit.h:25:
/usr/local/Cellar/icu4c/59.1/include/unicode/unistr.h:3025:7: error: delegating constructors are permitted only in C++11
      UnicodeString(ConstChar16Ptr(text)) {}
      ^~~~~~~~~~~~~
/usr/local/Cellar/icu4c/59.1/include/unicode/unistr.h:3087:7: error: delegating constructors are permitted only in C++11
      UnicodeString(ConstChar16Ptr(text), length) {}
      ^~~~~~~~~~~~~
/usr/local/Cellar/icu4c/59.1/include/unicode/unistr.h:3180:7: error: delegating constructors are permitted only in C++11
      UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
      ^~~~~~~~~~~~~
transliterator.cpp:101:60: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
  trans = Transliterator::createInstance(UnicodeString(id, id_len), UTRANS_FORWARD, p_error, status);
                                         ~~~~~~~~~~~~~     ^~~~~~
transliterator.cpp:106:34: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
  u_txt = new UnicodeString(txt, txt_len);
              ~~~~~~~~~~~~~      ^~~~~~~
4 warnings and 3 errors generated.
make: *** [transliterator.o] Error 1

make failed, exit code 2

Installed successfully with

$ gem install charlock_holmes -- --with-cxxflags=-std=c++11

Ok, I’ve found out the problem was with the icu4c 59.1 version. I’ve installed the 57.1 version and it’s all good! So, if you’re on Mac you’ll just have to:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/9b26ef0bad5f88dc5096a88483b38d8155d76c78/Formula/icu4c.rb

and it will install the 57.1 version (using an old homebrew formula)

and then you just have to:

bundle config build.charlock_holmes --with-icu-dir=/usr/local/opt/icu4c
bundle install

😄

fixed in #116

Note that if your Gemfile or .gemspec requires 0.7.3 explicitly, you need to install the correct version. This worked for me:

gem install charlock_holmes -v 0.7.3 -- --with-cxxflags=-std=c++11

Make sure gem list charlock_holmes shows an installed version that matches what you have in Gemfile.lock

I had the same problem. 0.7.4 worked for me, but 0.7.3 and 0.7.5 did not. ¯\_(ツ)_/¯

☝️ This also worked for me with 0.7.3.