oneclick / rubyinstaller2

MSYS2 based RubyInstaller for Windows
https://rubyinstaller.org
BSD 3-Clause "New" or "Revised" License
644 stars 248 forks source link

Cannnot gem install exif. Win 10, cant find libexif after pacman -S mingw-w64-x86_64-libexif make failed, exit code 2 #352

Closed bradkrane closed 10 months ago

bradkrane commented 10 months ago

What problems are you experiencing?

Cannot gem install exif on Windows 10.0.19045

Steps to reproduce

Install rubyinstaller-devkit-3.2.2-1-x64.exe Run: gem install exif

I've also tried ridk exec pacman -S mingw-w64-x86_64-libexif then gem install exif & gem install exif --platform ruby -- --use-system-libraries with same outcome. How can I correctly specify the path to the lib so it will compile or fix whatever is broken? Thanks!

C:\Users\Brad Krane\Documents\src\exif>gem install exif
Building native extensions. This could take a while...
ERROR:  Error installing exif:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4/ext/exif
C:/Ruby32-x64/bin/ruby.exe extconf.rb
checking for -lexif... no
checking for libexif/exif-data.h... no
checking for libexif >= 0.6.22... no
checking for libexif >= 0.6.23... no
checking for whether -D LIBEXIF_VERSION='"unknown"' is accepted as CFLAGS... yes
creating Makefile

current directory: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4/ext/exif
make DESTDIR\= sitearchdir\=./.gem.20230813-29328-sitiig sitelibdir\=./.gem.20230813-29328-sitiig clean

current directory: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4/ext/exif
make DESTDIR\= sitearchdir\=./.gem.20230813-29328-sitiig sitelibdir\=./.gem.20230813-29328-sitiig
generating exif-x64-mingw-ucrt.def
compiling data.c
data.c:4:10: fatal error: libexif/exif-data.h: No such file or directory
    4 | #include <libexif/exif-data.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:248: data.o] Error 1

make failed, exit code 2

Gem files will remain installed in C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4 for inspection.
Results logged to C:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/exif-2.2.4/gem_make.out

C:\Users\Brad Krane\Documents\src\exif>ridk exec pacman -S mingw-w64-x86_64-libexif
resolving dependencies...
looking for conflicting packages...

Packages (1) mingw-w64-x86_64-libexif-0.6.24-2

Total Installed Size:  3.09 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                                                                                           [#######################################################################] 100%
(1/1) checking package integrity                                                                                         [#######################################################################] 100%
(1/1) loading package files                                                                                              [#######################################################################] 100%
(1/1) checking for file conflicts                                                                                        [#######################################################################] 100%
(1/1) checking available disk space                                                                                      [#######################################################################] 100%
:: Processing package changes...
(1/1) installing mingw-w64-x86_64-libexif                                                                                [#######################################################################] 100%

C:\Users\Brad Krane\Documents\src\exif>dir C:\Ruby32-x64\msys64\mingw64\include\libexif
 Volume in drive C has no label.
 Volume Serial Number is ECA4-34A2

 Directory of C:\Ruby32-x64\msys64\mingw64\include\libexif

2023-08-13  05:43    <DIR>          .
2023-08-13  05:43    <DIR>          ..
2022-02-12  01:35             1,563 exif-byte-order.h
2022-02-12  01:35             5,598 exif-content.h
2022-02-12  01:35             1,461 exif-data-type.h
2022-02-12  01:35             8,948 exif-data.h
2022-02-12  01:35             6,316 exif-entry.h
2022-02-12  01:35             1,981 exif-format.h
2022-02-12  01:35             1,675 exif-ifd.h
2022-02-12  01:35             4,301 exif-loader.h
2022-02-12  01:35             3,452 exif-log.h
2022-02-12  01:35             2,654 exif-mem.h
2022-02-12  01:35             4,333 exif-mnote-data.h
2022-02-12  01:35            11,334 exif-tag.h
2022-02-12  01:35             5,951 exif-utils.h
2022-02-12  01:35                76 _stdint.h
              14 File(s)         59,643 bytes
               2 Dir(s)  172,015,104,000 bytes free

C:\Users\Brad Krane\Documents\src\exif>gem install exif
Building native extensions. This could take a while...
ERROR:  Error installing exif:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4/ext/exif
C:/Ruby32-x64/bin/ruby.exe extconf.rb
checking for -lexif... no
checking for libexif/exif-data.h... no
checking for libexif >= 0.6.22... no
checking for libexif >= 0.6.23... no
checking for whether -D LIBEXIF_VERSION='"unknown"' is accepted as CFLAGS... yes
creating Makefile

current directory: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4/ext/exif
make DESTDIR\= sitearchdir\=./.gem.20230813-19312-ylqpfe sitelibdir\=./.gem.20230813-19312-ylqpfe clean

current directory: C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4/ext/exif
make DESTDIR\= sitearchdir\=./.gem.20230813-19312-ylqpfe sitelibdir\=./.gem.20230813-19312-ylqpfe
generating exif-x64-mingw-ucrt.def
compiling data.c
data.c:4:10: fatal error: libexif/exif-data.h: No such file or directory
    4 | #include <libexif/exif-data.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:248: data.o] Error 1

make failed, exit code 2

Gem files will remain installed in C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/exif-2.2.4 for inspection.
Results logged to C:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/exif-2.2.4/gem_make.out

What's the output from ridk version?

C:\Users\Brad Krane\Documents\src\exif>ridk version

ruby: path: C:/Ruby32-x64 version: 3.2.2 platform: x64-mingw-ucrt cc: gcc.exe (Rev10, Built by MSYS2 project) 12.2.0 ruby_installer: package_version: 3.2.2-1 git_commit: 83df213 msys2: path: C:\Ruby32-x64\msys64 cc: gcc (Rev1, Built by MSYS2 project) 13.2.0 sh: GNU bash, version 5.2.15(1)-release (x86_64-pc-msys) os: Microsoft Windows [Version 10.0.19045.3208]

C:\Users\Brad Krane\Documents\src\exif>ruby -v ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]

mohits commented 10 months ago

Hi! I was able to get into this but unfotunately, I don't have the full understanding of the setup to be able to help, so we will need some help from someone else also.

First: I did ridk enable and then ridk exec pacman -S mingw-w64-x86_64-libexif which installed exif into: C:\Ruby31-x64\msys64\mingw64 (lib, include\libexif).

I looked through running make --trace and found that the include paths were:

-I.
-I/C/Ruby31-x64/include/ruby-3.1.0/x64-mingw-ucrt
-I/C/Ruby31-x64/include/ruby-3.1.0/ruby/backward
-I/C/Ruby31-x64/include/ruby-3.1.0

This excluded C:\Ruby31-x64\msys64\mingw64\include\ under which libexif has the files that are needed. I temporarily edited the Makefile to include the above path:

INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir) -I /C/Ruby31-x64/msys64/mingw64/include

It now compiled but did not still failed to build. The trace showed that the lib path did not include the path where the libexif.a existed. Again, I patched the Makefile to include C:\Ruby31-x64\msys64\mingw64\lib

LIBPATH =  -L. -L$(libdir) -L/C/Ruby31-x64/msys64/mingw64/lib

The final issue was that -lexif was not in the list of libraries to build together (I think because extconf.rb did not find the library. So, again, I modified the Makefile:

LIBS = $(LIBRUBYARG_SHARED)  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt -lexif

Finally, it builds.

I don't know what is the correct way to factor all this back into the extconf.rb so that it works correctly - or if something else should have been done.

Hopefully someone can help based on the information that I have included.

MSP-Greg commented 10 months ago

@bradkrane

Ruby 3.2 is a 'ucrt' build, you installed the 'mingw' package.

Try pacman -S mingw-w64-ucrt-x86_64-libexif

I'm using Ruby master, and the gem installed properly.

EDIT: Starting with Ruby 3.1, RubyInstaller builds use the ucrt tool chain. So, the pacman 'prefix' for Ruby 3.0 and earlier is mingw-w64-x86_64-. For Ruby 3.1 and later, the prefix is mingw-w64-ucrt-x86_64-.

I just installed the gem using Ruby 3.2, and it also installed.

mohits commented 10 months ago

I guess that was the missing link in my investigation. Thanks for correcting that.

What's the correct way for:

MSP-Greg commented 10 months ago

Gem owners can add something similar to the below to their gemspec:

if spec.respond_to?(:metadata=)
  spec.metadata ||= {}
  spec.metadata["msys2_mingw_dependencies"] = "libexif"
end

I believe it is possible to have a version constraint on the package.

Otherwise, it's up to the person installing the gem.

mohits commented 10 months ago

Thanks, I will try to document this some place.

bradkrane commented 10 months ago

@MSP-Greg

Try pacman -S mingw-w64-ucrt-x86_64-libexif

That did it, thanks for the help.

I've opened bradkrane/exif#1 with the gem to add the mingw libexif dependency.

bradkrane commented 10 months ago

Correction pull request tonytonyjan/exif#34