Bug #16651

Extensions Do Not Compile on Mingw64

Added by cfis (Charlie Savage) 11 months ago. Updated 3 months ago.

Target version:
ruby -v:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x64-mingw32]


When mkmf.rb creates a Makefile for an extension, it will generate something that looks like this:

srcdir = .
topdir = C/MSYS64/USR/LOCAL/ruby-2.7.0/include/ruby-2.7.0
hdrdir = $(topdir)
arch_hdrdir = C:/MSYS64/USR/LOCAL/ruby-2.7.0/include/ruby-2.7.0/x64-mingw32

Notice the topdir path is c/ without the ":" Its only the topdir that does this, all other paths in the makefile use the "c:/" style.

mkmf.rb intentionally does that, see line 1098:

  def mkintpath(path)
    # mingw uses make from msys and it needs special care
    # converts from C:\some\path to /C/some/path
    path = path.dup!('\\', '/')
    path.sub!(/\A([A-Za-z]):(?=\/)/, '/\1') <-------- This line

But this is wrong, and causes errors like this (this is compiling the debase gem but it doesn't matter what c extension you use):

make: *** No rule to make target 'C/MSYS64/USR/LOCAL/ruby-2.7.0/include/ruby-2.7.0/ruby.h', needed by 'breakpoint.o'. Stop.

The fix is simple, just delete that line. The makefile should look like this:

srcdir = .
topdir = C:/MSYS64/USR/LOCAL/ruby-2.7.0/include/ruby-2.7.0
hdrdir = $(topdir)
arch_hdrdir = C:/MSYS64/USR/LOCAL/ruby-2.7.0/include/ruby-2.7.0/x64-mingw32

Note I'm not the first person to see this, but I've just been manually fixing it over the years. Would be good to really fix it.

Note some of those tickets put the blame on using mingw-make versus msys make. But on my system, neither work with the "c/" style path but both work with the "c:/" style path.

Updated by cfis (Charlie Savage) 3 months ago

This is still and issue with Ruby 2.7.2.

The offending line of code is now at line 1908 in mkmf.rb.

Updated by nobu (Nobuyoshi Nakada) 3 months ago

It would replace "C:/MSYS64/..." as "/C/MSYS64/...".
Where did a slash go?

Also available in: Atom PDF