Windows 7 - building win32/api gem


#1

Hi Guys,

I have been trying to install win32-api 1.4.0 gem on windows 7 x64 but
no success.

When i install x86 version, require ‘win32/api’ gives me following
error:

LoadError: 193: %1 is not a valid Win32 application. -
c:/ruby/lib/ruby/gems/1.9.1/gems/win32-api-1.4.0-x86-mswin32-60/lib/win32/api.so
from (irb):1:in require' from (irb):1 from c:/ruby/bin/irb.bat:20:in

My ruby:
ruby 1.9.1p0 (2009-01-30 revision 21907) [x64-mswin64_80]

My gems:
1.3.1

I have VS2008 installed and even managed to create a makefile but it
complains about following:

C:>gem install win32-api
Building native extensions. This could take a while…
ERROR: Error installing win32-api:
ERROR: Failed to build gem native extension.

c:/ruby/bin/ruby.exe extconf.rb install win32-api
checking for strncpy_s()… yes
creating Makefile

nmake

Microsoft ® Program Maintenance Utility Version 9.00.21022.08
Copyright © Microsoft Corporation. All rights reserved.

    c:\ruby\bin\ruby -e "puts 'EXPORTS', 'Init_api'"  >

api-x64-mswin64_80.def
cl -nologo -I. -Ic:/ruby/include/ruby-1.9.1/x64-mswin64_80
-Ic:/ruby/include/ruby-1.9.1/ruby/backward -Ic:/ruby/include/ruby-1.9.1
-Iwin32 -MD -Zi -O2b
2xty- -Zm600 -DHAVE_STRNCPY_S -D_CRT_SECURE_NO_DEPRECATE
-D_CRT_NONSTDC_NO_DEPRECATE -Foapi.obj -c -Tcwin32/api.c
api.c
cl -nologo -LD -Feapi.so api.obj msvcr80-ruby191.lib
oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib -link
-incremental:no -debug -opt:re
f -opt:icf -dll -libpath:"." -libpath:“c:/ruby/lib”
-implib:api-x64-mswin64_80.lib -pdb:api-x64-mswin64_80.pdb
-def:api-x64-mswin64_80.def
Creating library api-x64-mswin64_80.lib and object
api-x64-mswin64_80.exp
api.obj : error LNK2019: unresolved external symbol _rb_num2long
referenced in function _NUM2LONG
api.obj : error LNK2019: unresolved external symbol _rb_int2big
referenced in function _LONG2NUM
api.obj : error LNK2019: unresolved external symbol _rb_uint2big
referenced in function _ULONG2NUM
api.obj : error LNK2019: unresolved external symbol
_rb_data_object_alloc referenced in function _api_allocate
api.obj : error LNK2019: unresolved external symbol _rb_raise referenced
in function _StringError
api.obj : error LNK2019: unresolved external symbol _rb_iv_set
referenced in function _callback_init
api.obj : error LNK2019: unresolved external symbol _rb_str_new_cstr
referenced in function _callback_init
api.obj : error LNK2019: unresolved external symbol _rb_scan_args
referenced in function _callback_init
api.obj : error LNK2019: unresolved external symbol _rb_string_value_ptr
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_str_cat
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_str_new_shared
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_check_safe_obj
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_string_value
referenced in function _api_init
api.obj : error LNK2001: unresolved external symbol __imp__rb_eArgError
api.obj : error LNK2019: unresolved external symbol _rb_ary_push
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_ary_new
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_str_split
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_respond_to
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_intern
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_check_type
referenced in function _api_init
api.obj : error LNK2019: unresolved external symbol _rb_str_modify
referenced in function _CallbackFunction
api.obj : error LNK2019: unresolved external symbol _rb_num2ulong
referenced in function _CallbackFunction
api.obj : error LNK2019: unresolved external symbol _rb_funcall2
referenced in function _CallbackFunction
api.obj : error LNK2019: unresolved external symbol _rb_iv_get
referenced in function _CallbackFunction
api.obj : error LNK2019: unresolved external symbol _rb_str_new
referenced in function _api_call
api.obj : error LNK2019: unresolved external symbol _rb_define_const
referenced in function _Init_api
api.obj : error LNK2019: unresolved external symbol _rb_define_attr
referenced in function _Init_api
api.obj : error LNK2019: unresolved external symbol _rb_define_method
referenced in function _Init_api
api.obj : error LNK2019: unresolved external symbol
_rb_define_alloc_func referenced in function _Init_api
api.obj : error LNK2001: unresolved external symbol
__imp__rb_eRuntimeError
api.obj : error LNK2019: unresolved external symbol
_rb_define_class_under referenced in function _Init_api
api.obj : error LNK2001: unresolved external symbol __imp__rb_cObject
api.obj : error LNK2019: unresolved external symbol _rb_define_module
referenced in function _Init_api
api.so : fatal error LNK1120: 33 unresolved externals
NMAKE : fatal error U1077: ‘“C:\Program Files (x86)\Microsoft Visual
Studio 9.0\VC\BIN\cl.EXE”’ : return code ‘0x2’
Stop.

Gem files will remain installed in
c:/ruby/lib/ruby/gems/1.9.1/gems/win32-api-1.4.0 for inspection.
Results logged to
c:/ruby/lib/ruby/gems/1.9.1/gems/win32-api-1.4.0/ext/gem_make.out

Does anyone have any idea about building gem on windows? Or maybe you
have precompiled api.so on your x64 system.

I would appreciate your help.


#2

Hi,

2009/3/3 Stanislaw W. removed_email_address@domain.invalid:

    from (irb):1:in `require’
complains about following:
nmake
-D_CRT_NONSTDC_NO_DEPRECATE -Foapi.obj -c -Tcwin32/api.c
api.c

Does anyone have any idea about building gem on windows? Or maybe you
have precompiled api.so on your x64 system.

I guess you tried to build win32-api module with Visual C++ 9.0.
You must use the same compiler with the Ruby version(x64-mswin64_80).
After some trials and errors, I managed to build win32-api module with
Visual C++ 8.0.
You can download at http://121.78.227.9/win32-api-1.4.0/lib/win32/api.so

NB, Using win32utils on the 64bit Ruby is not tested.

Regards,

Park H.


#3

Thanks for your help, it worked like a charm.

For my future reference, is VC++ 8.0 included in Visual Studio 2005?


#4

And BTW, would you mind sharing how to setup build environment and how
to build extensions on windows? I am installing VS2005 as we speak


#5

Hi,

2009/3/4 Stanislaw W. removed_email_address@domain.invalid:

And BTW, would you mind sharing how to setup build environment and how
to build extensions on windows? I am installing VS2005 as we speak

Build environment is just Visual Studio 2005 x64 command prompt.

The ruby 1.9.1p0 (2009-01-30 revision 21907) [x64-mswin64_80]
distribution lacks
win32.h file in \include\ruby-1.9.1\ruby folder.
Coping win32.h from ruby 1.9.1p0 source code to the above folder is
required.

This subject is more suitable on win32utils-devel mailing list.
Please join at http://rubyforge.org/mail/?group_id=85 for more
discussion.

Regards,

Park H.