Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

extending ruby with c++ on windows

14 views
Skip to first unread message

Al Lo

unread,
Nov 19, 2009, 7:40:32 AM11/19/09
to
hello everyone
i need help with extending ruby with c on windows
i've got ruby with version 1.9.1 [i386-mingw32]
and mingw32-make with versions 3.8 and 3.81
i wrote a simply cpp file and extconf.rb as is described here:
http://onlamp.com/pub/a/onlamp/2004/11/18/extending_ruby.html
then i run "ruby extconf.rb". so i get a Makefile.

running mingw32-make (v3.80) i get error:
makefile:145: *** target pattern contains no `%'. Stop.

if i run mingw32-make i get this strings:
makefile:154: warning: overriding commands for target `C:/Program'
makefile:148: warning: ignoring old commands for target `C:/Program'
mingw32-make: *** No rule to make target `"/C/Program', needed by
`Welcomer.o'.
Stop.

don't know what to do. is there any way to fix this? or the way to by
pass this?
--
Posted via http://www.ruby-forum.com/.

Reid Thompson

unread,
Nov 19, 2009, 7:42:49 AM11/19/09
to

not sure if it's the problem or not, but i'd try everything with a directory hierarchy that does not contain
any spaces in any of the directory or filenames.

Luis Lavena

unread,
Nov 19, 2009, 8:02:02 AM11/19/09
to
On Nov 19, 9:42 am, Reid Thompson <reid.thomp...@ateb.com> wrote:
> Al Lo wrote:
> > hello everyone
> > i need help with extending ruby with c on windows
> > i've got ruby with version 1.9.1 [i386-mingw32]
> > and mingw32-make with versions 3.8 and 3.81
>
> > running mingw32-make (v3.80) i get error:
> > makefile:145: *** target pattern contains no `%'.  Stop.
>
> > if i run mingw32-make i get this strings:
> > makefile:154: warning: overriding commands for target `C:/Program'
> > makefile:148: warning: ignoring old commands for target `C:/Program'
> > mingw32-make: *** No rule to make target `"/C/Program', needed by
> > `Welcomer.o'.
> >  Stop.
>
>
> not sure if it's the problem or not, but i'd try everything with a directory hierarchy that does not contain
> any spaces in any of the directory or filenames.

Yes, that is most likely the problem.

MinGW and MSYS, the tools used to compile should never be installed in
a path with spaces. Neither your code should be in a path with spaces.

Just avoid them

--
Luis Lavena

Al Lo

unread,
Nov 20, 2009, 3:59:03 AM11/20/09
to
Thank you for answers. it was good idea.
but i still have problems.
i installed ruby in folder without spaces. relaunched "ruby extconf.rb"
and "make" than, as in tutorial. executing "make" with version 3.80 i
got the same error as before (makefile:145: *** target pattern contains
no `%'. Stop.). building with "make" with version 3.81 i got next
message:

mingw32-make: *** No rule to make target
`/C/Ruby19/include/ruby-1.9.1/ruby.h',

needed by `Welcomer.o'. Stop.
i fixed in makefile row with path (corrected "/C/" to "C:/") and got
this response:
C:\temp\c2r>mingw32-make
process_begin: CreateProcess(NULL, rm -f Welcomer.so, ...) failed.
make (e=2): ═х єфрхЄё  эрщЄш єърчрээ√щ Їрщы.
mingw32-make: [Welcomer.so] Error 2 (ignored)
g++ -shared -s -o Welcomer.so Welcomer.o -L. -LC:/Ruby19/lib -L.
-Wl,--enable-a
uto-image-base,--enable-auto-import -lmsvcrt-ruby191 -lshell32
-lws2_32

As i understand, error 2 means "The system cannot find the file
specified".

This command generates two files: "Welcomer.o" and "Welcomer.so". One
more question is "is it normal that make generates .so file? maybe .dll
will be more suitable".

Luis Lavena

unread,
Nov 20, 2009, 7:16:29 AM11/20/09
to
On Nov 20, 5:59 am, Al Lo <lomov...@gmail.com> wrote:
> Thank you for answers. it was good idea.
> but i still have problems.
> i installed ruby in folder without spaces. relaunched "ruby extconf.rb"
> and "make" than, as in tutorial. executing "make" with version 3.80 i
> got the same error as before (makefile:145: *** target pattern contains
> no `%'.  Stop.). building with "make" with version 3.81 i got next
> message:
>
> mingw32-make: *** No rule to make target
> `/C/Ruby19/include/ruby-1.9.1/ruby.h',
> needed by `Welcomer.o'.  Stop.
> i fixed in makefile row with path (corrected "/C/" to "C:/") and got
> this response:
> C:\temp\c2r>mingw32-make

You shouldn't be using mingw32-make, but instead the make that comes
with the DevKit (that is, using the wrapper make.bat)

>
> As i understand, error 2 means "The system cannot find the file
> specified".
>
> This command generates two files: "Welcomer.o" and "Welcomer.so". One
> more question is "is it normal that make generates .so file? maybe .dll
> will be more suitable".

".so" are use to load Ruby extension. While is a DLL, it serves no
purpose outside Ruby world.

--
Luis Lavena

Al Lo

unread,
Nov 21, 2009, 8:35:58 AM11/21/09
to
thanks for explanation. i will not take care about trying to get dll.

make.bat contains next text:
"@echo off
mingw32-make %*"
that's why i used "mingw32-make"

it is still difficult to understand to me why mkmf generates such wrong
pass with "/C/" in th beginning. there is this rows:
topdir = /C/Ruby19/include/ruby-1.9.1
hdrdir = /C/Ruby19/include/ruby-1.9.1

as i wrote, i fixed this rows and get makefile and ran make. there is
what i have on console:
C:\temp\c2r>make
g++ -I. -IC:/Ruby19/include/ruby-1.9.1/i386-mingw32
-IC:/Ruby19/include/ruby-1.9.1/ruby/backward
-IC:/Ruby19/include/ruby-1.9.1 -I. -O2 -g -Wall -Wno-parentheses
-o welcomer.o -c welcomer.cpp
g++ -shared -s -o welcomer.so welcomer.o -L. -LC:/Ruby19/lib -L.
-Wl,--enable-auto-image-base,--enable-auto-import -lmsvcrt-ruby191
-lshell32 -lws2_32

C:\temp\c2r>irb
irb(main):001:0> require 'welcomer'
LoadError: 127: =х эрщфхэр єърчрээр  яЁюЎхфєЁр. - Init_welcomer
C:/temp/c2r/welcomer.so
from (irb):1:in `require'
from (irb):1
from C:/Ruby19/bin/irb:12:in `<main>'

there are "welcomer.cpp" in attachments.
i can't get what i'm doing wrong.

Attachments:
http://www.ruby-forum.com/attachment/4270/welcomer.cpp

Al Lo

unread,
Nov 21, 2009, 8:38:28 AM11/21/09
to
got it.
i renaimed "weclomer.cpp" to "welcomer.c". and it works.

so there are two questions left:
1. how to get round mkmf to find cpp files
2. why mkmf generates Makefile with incorrect paths

Al Lo

unread,
Nov 21, 2009, 11:22:22 AM11/21/09
to
just founded answer to the second question. this path work if run make
from msys shell, not from dos.

Luis Lavena

unread,
Nov 21, 2009, 2:02:39 PM11/21/09
to
On Nov 21, 10:35 am, Al Lo <lomov...@gmail.com> wrote:
> thanks for explanation. i will not take care about trying to get dll.
>
> make.bat contains next text:
> "@echo off
> mingw32-make %*"
> that's why i used "mingw32-make"
>

Dunno where you got that make.bat, this is the original make.bat
content:

@ECHO OFF
SETLOCAL
SET DEVKIT=%~dp0..\devkit
SET PATH=%DEVKIT%\gcc\3.4.5\bin;%DEVKIT%\msys\1.0.11\bin
bash.exe --login -i -c "make %*"

> it is still difficult to understand to me why mkmf generates such wrong
> pass with "/C/" in th beginning. there is this rows:
> topdir = /C/Ruby19/include/ruby-1.9.1
> hdrdir = /C/Ruby19/include/ruby-1.9.1
>

mkmf will generate MSYS paths, used by msys-make, as you can see from
the wrapper make.bat

I recommend you clean your current DevKit installation and verify the
proper batch files are being used.

A second recommendation, unless you're really using C++ (which I doubt
since Ruby extension API is C), please name the files .c instead

--
Luis Lavena

Al Lo

unread,
Nov 21, 2009, 5:45:19 PM11/21/09
to
tyvm, luislavena.
this make.bat file was taken from qt. as qt bin folder was before mingw
in environment variables.
0 new messages