Project

General

Profile

Actions

Bug #13903

closed

cant compile ruby with /MT on windows

Added by rocifier (Ryan O'Connor) over 6 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-09-13 trunk 59863) [i386-mswin32_140]
[ruby-core:82811]

Description

steps:

  1. open VS2015 x86 Native Tools Command Prompt
  2. follow instructions in https://github.com/ruby/ruby/blob/trunk/win32/README.win32

most of the compilation completes including producing .lib files, but nmake finally errors out at this stage and the whole process doesn't complete:

compiling c:/Repositories/ruby/ext/bigdecimal/bigdecimal.c
bigdecimal.c
linking shared-object bigdecimal.so
   Creating library bigdecimal-i386-mswin32_140.lib and object bigdecimal-i386-mswin32_140.exp
bigdecimal.obj : error LNK2001: unresolved external symbol _rb_cNumeric
bigdecimal.obj : error LNK2001: unresolved external symbol _rb_eArgError
bigdecimal.obj : error LNK2001: unresolved external symbol _rb_eTypeError
bigdecimal.obj : error LNK2001: unresolved external symbol _rb_eZeroDivError
bigdecimal.obj : error LNK2001: unresolved external symbol _rb_eFloatDomainError
bigdecimal.obj : error LNK2001: unresolved external symbol _rb_eMathDomainError
../../.ext/i386-mswin32_140/bigdecimal.so : fatal error LNK1120: 6 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'

Trying other configure options such as --with-static-linked-extension cause different errors such as NMAKE : fatal error U1073: don't know how to make 'enc/libenc.lib'.

When I link to the static lib produced in a C++ project, I get many linking errors:

1>vcruntime140-ruby250-static.lib(random.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(marshal.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(util.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(rational.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(complex.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(math.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(numeric.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(vm.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(sprintf.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(bignum.obj) : error LNK2001: unresolved external symbol __imp___dclass
1>vcruntime140-ruby250-static.lib(numeric.obj) : error LNK2001: unresolved external symbol __imp___dsign
1>vcruntime140-ruby250-static.lib(complex.obj) : error LNK2001: unresolved external symbol __imp___dsign
1>vcruntime140-ruby250-static.lib(math.obj) : error LNK2001: unresolved external symbol __imp___dsign
1>vcruntime140-ruby250-static.lib(lgamma_r.obj) : error LNK2001: unresolved external symbol __imp___dsign
1>vcruntime140-ruby250-static.lib(marshal.obj) : error LNK2001: unresolved external symbol __imp__frexp
1>vcruntime140-ruby250-static.lib(numeric.obj) : error LNK2001: unresolved external symbol __imp__frexp
1>vcruntime140-ruby250-static.lib(bignum.obj) : error LNK2001: unresolved external symbol __imp__frexp
1>vcruntime140-ruby250-static.lib(rational.obj) : error LNK2001: unresolved external symbol __imp__frexp
1>vcruntime140-ruby250-static.lib(math.obj) : error LNK2001: unresolved external symbol __imp__frexp
1>vcruntime140-ruby250-static.lib(numeric.obj) : error LNK2001: unresolved external symbol __imp__round
1>vcruntime140-ruby250-static.lib(bignum.obj) : error LNK2001: unresolved external symbol __imp__round
1>vcruntime140-ruby250-static.lib(numeric.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>vcruntime140-ruby250-static.lib(thread.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>vcruntime140-ruby250-static.lib(enum.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>vcruntime140-ruby250-static.lib(compile.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>vcruntime140-ruby250-static.lib(marshal.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vcruntime140-ruby250-static.lib(lgamma_r.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vcruntime140-ruby250-static.lib(vm.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vcruntime140-ruby250-static.lib(bignum.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vcruntime140-ruby250-static.lib(compile.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vcruntime140-ruby250-static.lib(time.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vcruntime140-ruby250-static.lib(file.obj) : error LNK2001: unresolved external symbol __imp__umask
1>vcruntime140-ruby250-static.lib(process.obj) : error LNK2001: unresolved external symbol __imp__umask
1>OLDNAMES.lib(umask.obi) : error LNK2001: unresolved external symbol __imp__umask
Actions #1

Updated by rocifier (Ryan O'Connor) over 6 years ago

  • Description updated (diff)
  • ruby -v set to ruby 2.5.0dev (2017-09-13 trunk 59863) [i386-mswin32_140]

Updated by shevegen (Robert A. Heiler) over 6 years ago

Just for curiosity, ruby 2.4.x works for you on windows if you compile it?

Updated by rocifier (Ryan O'Connor) over 6 years ago

shevegen (Robert A. Heiler) wrote:

Just for curiosity, ruby 2.4.x works for you on windows if you compile it?

Hi, exactly the same errors for ruby_2_4 branch.

My goal is to link to the produced static library, so I supposed I need to ideally get --with-static-linked-extension working. Otherwise, is there a list of external lib dependencies I should be linking to before the ruby lib? So far I have only been able to guess at ws2_32.lib, but the maths stuff worries me since that should be build into MSVC compilers.

Updated by rocifier (Ryan O'Connor) over 6 years ago

shevegen (Robert A. Heiler) wrote:

Just for curiosity, ruby 2.4.x works for you on windows if you compile it?

I got both versions to build easily with an old VS2010 command prompt, but I still get the imp errors when I link to the static library. Am I missing some kind of configuration outside of --with-static-linked-extension?

EDIT: Seems I can compile everything if I run the command prompts with Administrator privileges. That solves most of my problem here. Anyone know about linking to the produced libraries?
If I link with vcruntime140-ruby250-static.lib then I get 121 undefined symbols like those listed above.
If I link to vcruntime140-ruby250.lib then I get just these two:
LNK2005 _getenv already defined in vcruntime140-ruby240.lib(vcruntime140-ruby240.dll) Engine.App C:\Repositories\ags\Solutions\Engine.App\libucrtd.lib(getenv.obj)
LNK2005 _fclose already defined in vcruntime140-ruby240.lib(vcruntime140-ruby240.dll) Engine.App C:\Repositories\ags\Solutions\Engine.App\libucrtd.lib(fclose.obj)

After some more investigation I have discovered that ruby is being compiled with /MD, how can I build it with /MT instead? Since the rest of my app is using /MT I suspect that mismatch is causing me issues. Sometimes I have got the library to link in my target app, but I get weird issues related to passing file pointers around the CRT boundaries, and would like to make ruby match all the other libs I am linking against.

Updated by MSP-Greg (Greg L) over 6 years ago

I'm not that familiar with MS build tools, but I think ruby is building with this file - appveyor.yml, which I believe is using 140. Test results here.

test-all failure may be due to conflicting OpenSSL versions, as the files exist both in the MSYS2/MinGW system and the OpenSSL-Win32 directory.

Actions #6

Updated by rocifier (Ryan O'Connor) over 6 years ago

  • Subject changed from cant compile ruby on windows to cant compile ruby with /MT on windows

Updated by rocifier (Ryan O'Connor) over 6 years ago

MSP-Greg (Greg L) wrote:

I'm not that familiar with MS build tools, but I think ruby is building with this file - appveyor.yml, which I believe is using 140. Test results here.

test-all failure may be due to conflicting OpenSSL versions, as the files exist both in the MSYS2/MinGW system and the OpenSSL-Win32 directory.

Do you know how to configure the project to build with /MTd? I am getting "unexpected ucrtbased.dll" when trying to link miniruby.exe

Updated by MSP-Greg (Greg L) over 6 years ago

rocifier (Ryan O'Connor) wrote:

Do you know how to configure the project to build with /MTd? I am getting "unexpected ucrtbased.dll" when trying to link miniruby.exe

Sorry, I don't. I assume you've built other projects with /MTd? I'm not much of a C type...

just noticed from prev:

If I link to vcruntime140-ruby250.lib then I get just these two:
LNK2005 _getenv already defined in vcruntime140-ruby240.lib(vcruntime140-ruby240.dll) Engine.App C:\Repositories\ags\Solutions\Engine.App\libucrtd.lib(getenv.obj)
LNK2005 _fclose already defined in vcruntime140-ruby240.lib(vcruntime140-ruby240.dll) Engine.App C:\Repositories\ags\Solutions\Engine.App\libucrtd.lib(fclose.obj)

Maybe a typo, but both ruby250 and ruby240 are listed. It should be one or the other, but not both?

Updated by rocifier (Ryan O'Connor) over 6 years ago

That was a typo, I've tried both 2.4 and 2.5 separately.

I'd also settle for rebuilding all the other libraries in the project to use /MD but I'd need to get /MDd building on Ruby. I tried overwriting the option by manually setting COMPILERFLAG = /MDd in the debug configured Makefile, which works until linking stage where I get

linking miniruby.exe
unexpected ucrtbased.dll
NMAKE : fatal error U1077: '.\miniruby.exe' : return code '0x1'
Stop.

EDIT: I'm not getting much assistance here and I'm making a little more progress trying to link with /MDd for debug configurations, but it's slow. I'm moving the conversation to here: https://stackoverflow.com/questions/46262403/embedding-ruby-in-vc-and-calling-ruby-setup-returns-tag-raise if anyone cares to join in and assist, I will buy you a beer

Updated by rocifier (Ryan O'Connor) over 6 years ago

This patch helped me understand the problem above: https://bugs.ruby-lang.org/issues/12644
After pasting the ucrtbased.dll from StarCraft II support folder into my build folder, I can now fully build ruby with /MDd and link it. You may close this issue.

Actions #11

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0