brianmario / charlock_holmes

Character encoding detection, brought to you by ICU
MIT License
1.04k stars 142 forks source link

Build error using GCC version 14 (Arch GNU/Linux) #173

Closed kktlnx closed 4 months ago

kktlnx commented 6 months ago

I'm not certain if the error is directly related to the compiler itself (I'm using Arch GNU/Linux with gcc/g++ 14.1.1) as I've noticed a new issue with the ICU version mentioned (#172). The logs are as follows:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/user/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/charlock_holmes-0.7.7/ext/charlock_holmes
/home/user/.asdf/installs/ruby/2.7.8/bin/ruby -I /home/user/.asdf/installs/ruby/2.7.8/lib/ruby/2.7.0 -r ./siteconf20240522-106487-1tjcca2.rb extconf.rb
checking for -licui18n... yes
checking for unicode/ucnv.h... yes
checking for -lz... yes
checking for -licuuc... yes
checking for -licudata... yes
creating Makefile

current directory: /home/user/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/charlock_holmes-0.7.7/ext/charlock_holmes
make "DESTDIR=" clean

current directory: /home/user/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/charlock_holmes-0.7.7/ext/charlock_holmes
make "DESTDIR="
compiling converter.c
compiling encoding_detector.c
compiling ext.c
compiling transliterator.cpp
In file included from /usr/include/unicode/unistr.h:39,
                 from /usr/include/unicode/translit.h:27,
                 from transliterator.cpp:5:
/usr/include/unicode/stringpiece.h:133:29: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type
  133 |             typename = std::enable_if_t<
      |                             ^~~~~~~~~~~
/usr/include/unicode/stringpiece.h:133:24: note: ‘std::enable_if_t’ is only available from C++14 onwards
  133 |             typename = std::enable_if_t<
      |                        ^~~
/usr/include/unicode/stringpiece.h:133:40: error: expected ‘>’ before ‘<’ token
  133 |             typename = std::enable_if_t<
      |                                        ^
In file included from /usr/include/unicode/uenum.h:25,
                 from /usr/include/unicode/utrans.h:22,
                 from /usr/include/unicode/translit.h:29:
/usr/include/unicode/localpointer.h:561:26: error: parameter declared ‘auto’
  561 | template <typename Type, auto closeFunction>
      |                          ^~~~
/usr/include/unicode/localpointer.h:573:76: error: template argument 2 is invalid
  573 |     explicit LocalOpenPointer(std::unique_ptr<Type, decltype(closeFunction)> &&p)
      |                                                                            ^
/usr/include/unicode/localpointer.h:583:78: error: template argument 2 is invalid
  583 |     LocalOpenPointer &operator=(std::unique_ptr<Type, decltype(closeFunction)> &&p) {
      |                                                                              ^
/usr/include/unicode/localpointer.h:599:59: error: template argument 2 is invalid
  599 |     operator std::unique_ptr<Type, decltype(closeFunction)> () && {
      |                                                           ^
/usr/include/unicode/uenum.h:69:1: note: invalid template non-type parameter
   69 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUEnumerationPointer, UEnumeration, uenum_close);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/unicode/uset.h:358:1: note: invalid template non-type parameter
  358 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer, USet, uset_close);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/unicode/utrans.h:258:1: note: invalid template non-type parameter
  258 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUTransliteratorPointer, UTransliterator, utrans_close);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:238: transliterator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/user/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/charlock_holmes-0.7.7 for inspection.
Results logged to /home/user/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/charlock_holmes-0.7.7/gem_make.out

An error occurred while installing charlock_holmes (0.7.7), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.7.7'` succeeds before bundling.

In Gemfile:
  charlock_holmes

To fix this, I changed the 37th line in the extconf.rb file from

$CXXFLAGS << ' -std=c++11'

to

$CXXFLAGS << ' -std=c++17'

and then build again. Here are steps:

gem fetch charlock_holmes -v '0.7.7'
gem spec charlock_holmes-0.7.7.gem --ruby > charlock.spec
gem unpack charlock_holmes-0.7.7.gem
mv charlock.spec charlock_holmes-0.7.7/
cd charlock_holmes-0.7.7

# now change code
# emacs -nw  file / code .

gem build charlock.spec
gem install ./charlock_holmes-0.7.7.gem
w-zygmuntowicz commented 6 months ago

If it's helpful, I just checked that the changes don't cause compilation errors on an older system (GCC 13.2.1 and ICU 72.4)

nerijunior commented 5 months ago

Same here.

raucao commented 5 months ago

Just ran into this, too. Tried the steps above, but the same error persists.

kktlnx commented 5 months ago

Just ran into this, too. Tried the steps above, but the same error persists.

Sorry to hear that, you can experiment with different flag settings too after a failed installation. A Makefile then appears in the directory and you can directly edit this file and compile with make until you get it right. In my distribution Also I have the option of installing the older gcc and use them as separate commands, you can then also use that commands in the Makefile.

rnestler commented 5 months ago

Actually just removing the flag altogether works for me as well. This should be preferred IMO, since the standard flags on a system should be fine.

rnestler commented 5 months ago

As a workaround one can also use gem install charlock_holmes -- --with-cxxflags='#' to comment out the following build flags :slightly_smiling_face: