extending ruby with c++ on windows

A

Al Lo

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?
 
R

Reid Thompson

Al said:
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?

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.
 
L

Luis Lavena

Al said:
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
 
A

Al Lo

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".
 
L

Luis Lavena

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.
 
A

Al Lo

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
 
A

Al Lo

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
 
A

Al Lo

just founded answer to the second question. this path work if run make
from msys shell, not from dos.
 
L

Luis Lavena

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
 
A

Al Lo

tyvm, luislavena.
this make.bat file was taken from qt. as qt bin folder was before mingw
in environment variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top