ruby-numo / numo-narray

Ruby/Numo::NArray - New NArray class library
http://ruby-numo.github.io/narray/
BSD 3-Clause "New" or "Revised" License
415 stars 41 forks source link

Fails to build on MSVC #141

Closed cfis closed 4 years ago

cfis commented 4 years ago

The gem fails to build on MSVC. The problem is that extconf.rb defines $objs like this:

srcs = %w(... types/bit ....}

But mkmf.rb strips that to this (notice that types/ gets removed - see line 2240 in mkmf.rb, $objs.collect! {|o| File.basename(o, ".*") << ext} unless $OBJEXT == "o")

bit.obj

So the makefile ends up like this:

SRCS = $(ORIG_SRCS) narray.c array.c step.c index.c ndloop.c data.c bit.c int8.c int16.c int32.c int64.c uint8.c uint16.c uint32.c uint64.c sfloat.c dfloat.c scomplex.c dcomplex.c robject.c math.c SFMT.c struct.c rand.c OBJS = narray.o array.o step.o index.o ndloop.o data.o types\bit.o types/int8.o types/int16.o types/int32.o types/int64.o types/uint8.o types/uint16.o types/uint32.o types/uint64.o types/sfloat.o types/dfloat.o types/scomplex.o types/dcomplex.o types/robject.o math.o SFMT.o struct.o rand.o

But then the rules are like this:

types/bit.c: C:/msys64/usr/local/ruby-2.6.3vc/lib/ruby/gems/2.6.0/gems/numo-narray-0.9.1.5/ext/numo/narray/gen/def/bit.rb $(DEPENDS) $(MAKEDIRS) $(@D) types ruby $(COGEN) -l -o $@ C:/msys64/usr/local/ruby-2.6.3vc/lib/ruby/gems/2.6.0/gems/numo-narray-0.9.1.5/ext/numo/narray/gen/def/bit.rb

The end result is this error:

linking shared-object numo/narray.so LINK : fatal error LNK1181: cannot open input file 'bit.obj' NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.23.28105\bin\HostX64\x64\cl.EXE"' : return code '0x2'

Not sure the best way to fix. My quick workaround is change lines like this:

types/bit.c: C:/msys64/usr/local/ruby-2.6.3vc/lib/ruby/gems/2.6.0/gems/numo-narray-0.9.1.5/ext/numo/narray/gen/def/bit.rb $(DEPENDS) $(MAKEDIRS) $(@D) types ruby $(COGEN) -l -o $@ C:/msys64/usr/local/ruby-2.6.3vc/lib/ruby/gems/2.6.0/gems/numo-narray-0.9.1.5/ext/numo/narray/gen/def/bit.rb

To lines like this:

bit.c: C:/msys64/usr/local/ruby-2.6.3vc/lib/ruby/gems/2.6.0/gems/numo-narray-0.9.1.5/ext/numo/narray/gen/def/bit.rb $(DEPENDS) $(MAKEDIRS) $(@D) types ruby $(COGEN) -l -o $@ C:/msys64/usr/local/ruby-2.6.3vc/lib/ruby/gems/2.6.0/gems/numo-narray-0.9.1.5/ext/numo/narray/gen/def/bit.rb

That forces the codegen to create bit.c, which then creates bit.obj, which then solves the problem.

cfis commented 4 years ago

I can confirm this is fixed - thanks!