Skip to content
barrie0482 edited this page Sep 13, 2010 · 11 revisions

Instructions to build a ruby extension for rrdtool v1.3.8 on win32 using Microsoft Visual C++ 2008 Express

Download

Note: The ruby gem included in the packages below require the RRDtool libraries to be available in the system path

RRDtool-1.3.8-win32-ruby1.8-perl5.10-Setup.exe
RRDtool-1.3.8-win32-ruby1.8-perl5.10-Setup.zip

References

While I am not using SWIG, I found the following reference useful.

Pre-requisites

  • Microsoft Visual C++ 2008 Express

Build Directory Structure

rrdtool_win32_build
- contrib
- cairo
- glib
- libpng
- libxml2
- pango
- zlib
- rrdtool-1.3.8
- bindings
– ruby
- doc
- examples
- netware
- po
- win32
- patch

Modify Ruby’s config.h

  1. Edit C:\ruby\lib\ruby\1.8\i386-mswin32\config.h.
  2. Comment out the following lines at the top of the file.

#if _MSC_VER != 1200
#error MSC version unmatch
#endif

This code will cause an error when compiling with Visual C++ 2008 Express.

Manifest file

The Manifest file information is from Use SWIG to Build a Ruby Extension to Wrap a Windows DLL

I found that the best way to embed the .manifest file is to edit the mkmf source code. You can modify the Makefile that is generated, but if you change the source code you’ll never have to worry about it again. If you used the Ruby One-click installer, mkmf.rb can be found at C:\ruby\lib\ruby\1.8\mkmf.rb.


# Line 1324
  mfile.print "$(RUBYARCHDIR)/" if $extout
  mfile.print "$(DLLIB): ", (makedef ? "$(DEFFILE) " : ""), "$(OBJS)\n"
  mfile.print "\t@-$(RM) $@\n"
  mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout
  # link_so = LINK_SO.gsub(/^/, "\t")
  # mfile.print link_so, "\n\n"
  # Add the lines below
  link_so = LINK_SO.gsub(/^/, "\t")
  mfile.print link_so, "\n"
  mfile.print "\tmt.exe -manifest $(DLLIB).manifest -outputresource:$(DLLIB);2\n" if $mswin
  mfile.print "\n\n"

This will add mt.exe -manifest $(DLLIB).manifest -outputresource:$(DLLIB);2 to the Makefile dependency for our output .so file if we’re building for Windows.

Setup Microsoft Visual Studio 2008 x86 tools environment

  • Run vcvarsall.bat" x86

    "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
    Setting environment for using Microsoft Visual Studio 2008 x86 tools.

Set environment variables

Set Ruby Variables


    set RUBY_INCLUDE=C:\ruby\lib\ruby\1.8\i386-mswin32
    set RUBY_LIB=C:\ruby\lib\msvcrt-ruby18.lib

Set Temp to c:\Temp – No spaces in directory or folder names


   set TEMP=c:\Temp

Patches for rrdruby main.c for rrdtool v1.3.8 on win32

There is currently one patches (located in the repository ) that needs to be applied to get the ruby extension library to compile with Microsoft Visual C++ 2008 Express Edition.

I use the "GNU patch for win32:http://gnuwin32.sourceforge.net/packages/patch.htm to apply the patches.

I normally copy the source files to be patched to a patch directory and apply the patches as shown below. Once the files are patched I backup the original files and copy in the patched files.

Apply patch to main.c

  • Located in the ruby directory.

> patch < main.diff
patching file main.c

Modify the ruby extconf.rb file


require 'mkmf'
# If you are compiling the Debug version you will need to change Release to Debug in the code below.
# ruby extconf.rb --with-rrd-include=C:/ruby/src/ruby-1.8.6-p111,../../src --with-rrd-lib=../../win32/Release

dir_config("rrd","C:/ruby/src/ruby-1.8.6-p111,../../src","../../win32/Release")
have_library("rrdlib", "rrd_create")
create_makefile("RRD")

Run the extconf.rb file to create the Makefile

If you are compiling the Debug version you will need to change Release to Debug in the code below.

Note: the positive answer when checking for rrd_create



> ruby extconf.rb --with-rrd-include=C:/ruby/src/ruby-1.8.6-p111,../../src --with-rrd-lib=../../win32/Release
checking for rrd_create() in rrdlib.lib... yes
creating Makefile

Run nmake – lots of warnings, not sure if this is good


D:\projects\rrdtool\rrdtool-1.3.8\bindings\ruby>nmake

Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl -nologo -I. -I. -IC:/ruby/lib/ruby/1.8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6 -IC:/ruby/src/ruby-1.8.6-p111,../../src -c -Tcmain.c
cl : Command line warning D9035 : option 'Og-' has been deprecated and will be removed in a future release
cl : Command line warning D9002 : ignoring unknown option '-G6'
main.c
d:\projects\rrdtool\rrdtool-1.3.8\src\../win32/config.h(36) : warning C4005: 'isinf' : macro redefinition
        c:\ruby\lib\ruby\1.8\i386-mswin32\missing.h(71) : see previous definition of 'isinf'
d:\projects\rrdtool\rrdtool-1.3.8\src\../win32/config.h(37) : warning C4005: 'isnan' : macro redefinition
        c:\ruby\lib\ruby\1.8\i386-mswin32\win32/win32.h(234) : see previous definition of 'isnan'
d:\projects\rrdtool\rrdtool-1.3.8\src\../win32/config.h(38) : warning C4005: 'finite' : macro redefinition
        c:\ruby\lib\ruby\1.8\i386-mswin32\win32/win32.h(237) : see previous definition of 'finite'
d:\projects\rrdtool\rrdtool-1.3.8\src\../win32/config.h(39) : warning C4005: 'snprintf' : macro redefinition
        c:\ruby\lib\ruby\1.8\i386-mswin32\win32/win32.h(204) : see previous definition of 'snprintf'
main.c(161) : warning C4047: '=' : 'rrd_info_t *' differs in levels of indirection from 'int'
main.c(200) : warning C4047: 'function' : 'RRDFUNC' differs in levels of indirection from 'rrd_info_t *(__cdecl *)(int,char **)'
main.c(200) : warning C4024: 'rb_rrd_infocall' : different types for formal and actual parameter 1
main.c(207) : warning C4047: 'function' : 'RRDFUNC' differs in levels of indirection from 'rrd_info_t *(__cdecl *)(int,char **)'
main.c(207) : warning C4024: 'rb_rrd_infocall' : different types for formal and actual parameter 1
main.c(214) : warning C4047: 'function' : 'RRDFUNC' differs in levels of indirection from 'rrd_info_t *(__cdecl *)(int,char **)'
main.c(214) : warning C4024: 'rb_rrd_infocall' : different types for formal and actual parameter 1
        cl -nologo -LD -FeRRD.so main.obj msvcrt-ruby18.lib rrdlib.lib  oldnames.lib user32.lib advapi32.lib ws2_32.lib
 -link -incremental:no -debug -opt:ref -opt:icf -dll -libpath:"." -libpath:"C:/ruby/lib" -libpath:"../../win32/Release"
-def:RRD-i386-mswin32.def -implib:RRD-i386-mswin32.lib -pdb:RRD-i386-mswin32.pdb
rrdlib.lib(rrd_error.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to
the link command line to improve linker performance
   Creating library RRD-i386-mswin32.lib and object RRD-i386-mswin32.exp
Generating code
Finished generating code
        mt.exe -manifest RRD.so.manifest -outputresource:RRD.so;2
Microsoft (R) Manifest Tool version 5.2.3790.2076
Copyright (c) Microsoft Corporation 2005.
All rights reserved.