Jari Williamsson wrote:
config.h is system-specific and it should build when you call win32\configure.bat with your environment set up for the C++ Builder compiler and tools.
To run it with C++ Builder, you need to build from sources to create a compatible .lib to link with your project. AFAIK, it's basically these steps for any Windows C++ compiler.
1. Go to a command prompt that has the settings for the compiler and make tools
2. Create a folder where you want your build and go there
3. Call win32\configure.bat to build config.h and the mak file
4. Run the make tool
5. In your C++ project, link with a lib that was created during the make
In theory, that's what should make it work. Let me know how it works.
Best regards,
Jari Williamsson
HI Jari
Thanks for the advice and pointing me in the correct direction. The installed version (in InstantRails) did have a folder for bcc32. Here's what I did, starting from that (mostly following the advice in the Readme there).
[Getting Ruby built on Borland C++ Builder]
1. From a command window, created a new folder called brb - the compiler, linker, etc. was in the path (Your step 1)
2. Ran bcc32\configure to create some files (incl config.h)
3. make
4. This died halfway through because it could not find c0x32.obj though it was in the BDS\4.0\lib directory. To make this work, I went to the Makefile.sub and updated it to pass the OBJ file path to the ilink32 executable:
LD = ilink32 -q -Gn -j"D:\Program Files\Borland\BDS\4.0\lib\"
5. make (this worked now)
6. make test
7. make DESTDIR="E:\rb_bcc" install
After doing all this, I had the config.h that I needed (in the ruby\src\ruby-1.8.6\brb directory) and the static libs (bccwin32-ruby18-static.lib, bccwin32-ruby18.lib) in E:\rb_bcc\lib\ and the DLL (bccwin32-ruby18.dll) in E:\rb_bcc\bin
No idea yet about the performance of Ruby when compiled with Borland C++.
[Building my application]
For the application, I chose the sample code in 'Programming Ruby' that shows how to embed Ruby in your application.
1. In Borland C++ Builder, I chose to build a C++ console application. When I tried to link and build this, it gave me lots of errors about re-definition (some shown below)
[C++ Error] stdio.h(393): E2167 '_strerror(const char *)' was previously declared with the language 'C'
[C++ Error] stdio.h(400): E2167 '_wperror(const wchar_t *)' was previously declared with the language 'C'
[C++ Error] stdio.h(439): E2167 'perror(const char *)' was previously declared with the language 'C'
2. Then, I created the same thing as a C application and tried to link it with the static library. Still no go! I got a few errors for undefined references (below):
[Linker Error] Error: Unresolved external '_errno' referenced from E:\RB_BCC\LIB\BCCWIN32-RUBY18-STATIC.LIB|file
[Linker Error] Error: Unresolved external '__doserrno' referenced from E:\RB_BCC\LIB\BCCWIN32-RUBY18-STATIC.LIB|win32
[Linker Error] Error: Unresolved external 'WSAEnumProtocolsA' referenced from E:\RB_BCC\LIB\BCCWIN32-RUBY18-STATIC.LIB|win32
[Linker Error] Error: Unresolved external 'WSASocketA' referenced from E:\RB_BCC\LIB\BCCWIN32-RUBY18-STATIC.LIB|win32
3. Not sure what to do with it at this stage. I found a reference that I had seen earlier
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/73397
and tried to create it as a project to link with the DLL. That worked!!
I can now call a simple Ruby script from my C program. Now, I need to do 3 more things:
1. Rebuild ruby taking into account some advice about the memory manager.
2. Figure out how to work C++ with Ruby since my current application uses all the usual pretty things that Builder offers (and needs C++ for it). This may help a bit: ruby embedded into c++
3. Figure out how gems work when accessed from embedded Ruby.
I'm sorry that this is a long post but I wanted to jot down all the stuff I did so that it was available to the next person who may want to do this. I'm not done yet, but I'd like to put all this down into a blog post once it all works. But, the above 3 steps stand in the way.
Again, Jari - thanks for getting me started.
Cheers
Mohit.