Fix the Win32 build for executable and perl-shared library.
[rrdtool.git] / NT-BUILD-TIPS.txt
1 Compiling RRDtool 1.1.x on Win32 with Microsoft Visual C++:
2 ---------------------------------------------------------------
3 7/29/04 Jake Brutlag
4
5 As of Jan 2004, code for libraries utilized by rrdtool 
6 (png, libart, freetype, and zlib) is no longer distributed with
7 rrdtool. This requires some changes to the compile process on
8 Win32. The solution described here is to compile rrdtool to
9 link against these libraries dynamically. There is an advantage
10 to this approach: namely the rrdtool distribution doesn't have to
11 worry about how to compile these libraries on Win32. In theory,
12 since others already provide and maintain Win32 binaries for these
13 libraries the users don't have to worry about how to compile them
14 either. The disadvantage of this approach is that the DLLs for
15 these libraries must be available on the hosts where rrdtool will run.
16
17 Here are step by step instructions for compiling rrdtool.exe and
18 the perl shared library (RRDS.dll) with Microsoft Visual C++ 6.0.
19 (1) Download libraries rrdtool depends on from GnuWin32:
20 http://gnuwin32.sourceforge.net/
21 For freetype, libpng, and zlib download the "Complete Package"; each of
22 these will be a self-extracting self-installing executable.
23 For libart, download both the "Binaries" and "Developer Files" packages.
24 Unfortunately at this time GnuWin32 doesn't provide the "Complete Package"
25 installer for libart. Perhaps by the time you are following these
26 instructions GnuWin32 will have a "Complete Package" for libart.
27 (2) Install the GnuWin32 libraries by running the executables for freetype,
28 libpng, and zlib. These instructions and the Visual C++ project files
29 distributed with rrdtool assume that you will use the default install
30 location: C:\Program Files\GnuWin32. Extract the two zip files for libart,
31 libart-2.3.3-bin.zip and libart-2.3.3-1-lib.zip into the GnuWin32 directory;
32 the appropriate libart files will be added to the include, lib, and bin
33 subdirectories.
34 (3) Add C:\Program Files\GnuWin32\bin to the PATH (Control Panel ->
35 System -> Advanced -> Environment Variables).
36 (4) Start Microsoft Visual C++ 6.0. Load the workspace file, rrdtool.dsw,
37 from the src subdirectory of your rrdtool code directory.
38 (5) Compile the Release build of the rrdtool project (since rrdtool depends
39 on the rrd project, the rrd library will also be compiled). At this
40 time, the compile will fail in zconf.h, a zlib header file. The problem
41 is a preprocessor directive that loads unistd.h. Open zconf.h in VC++
42 (this file is in C:\Program Files\GnuWin32\include) and find the following
43 code block:
44
45 #if 1           /* HAVE_UNISTD_H -- this line is updated by ./configure */
46 #  include <sys/types.h> /* for off_t */
47 #  include <unistd.h>    /* for SEEK_* and off_t */
48 #  ifdef VMS
49 #    include <unixio.h>   /* for off_t */
50 #  endif
51 #  define z_off_t  off_t
52 #endif 
53
54 Change it to reads as follows (this is code from zlib-1.1.4):
55
56 #if HAVE_UNISTD_H
57 #  include <sys/types.h> /* for off_t */
58 #  include <unistd.h>    /* for SEEK_* and off_t */
59 #  ifdef VMS
60 #    include <unixio.h>   /* for off_t */
61 #  endif
62 #  define z_off_t  off_t
63 #endif 
64
65 Note that it is actually just a one line change. Save the file and
66 recompile rrdtool. By the time you are following these instructions
67 this issue with zconf.h may be resolved.
68 (6) At this point, you can run the executable rrdtool.exe in the
69 src\toolrelease subdirectory. Note that if you wish to run rrdtool
70 on other machines, you will need the following DLLs installed (on the
71 path) on those machines:
72 zlib1.dll
73 libpng12.dll
74 libart_lgpl.dll
75 freetype6.dll
76 msvcrt.dll
77 The names of the first four DLLs might vary from what is listed here
78 depending on the versions of the packages you downloaded from GnuWin32.
79 The fifth DLL, msvcrt.dll, is a system DLL for most versions of Windows.
80 If you are running on old version of Windows, you can install/upgrade to
81 IE4.0 to get this DLL.
82 (7) To compile the perl-shared library, open a Command Prompt (DOS box)
83 and cd to the bindings\perl-shared subdirectory.
84 (8) Run vcvars32.bat; this batch file, in your vc98\bin directory will
85 set necessary environment options for command line compiling.
86 (9) In bindings\perl-shared, run
87 perl ntmake.pl
88 nmake
89 nmake test
90 If nmake test succeeds, you are good to go. RRDs.dll is in 
91 blib\arch\auto\RRDs. If you plan to install via the Active State ppm
92 tool, tar and gzip the blib directory. You can use the RRDs.ppd file
93 in bindings\perl-shared directory. Remember that as in the case of
94 rrdtool.exe you will need the DLLs listed in (6) on the machine where
95 you are going to use RRDs.dll.
96
97 Microsoft Visual C++ 7.1 (.NET 2003):
98
99 Unfortunately, this is more difficult than with VC++ 6.0. The problem
100 is that by default the C runtime dll for VC++ 7.1 is msvcr71.dll rather
101 than msvcrt.dll. The GnuWin32 library binaries are all compiled
102 to use msvcrt.dll and you can't mix msvcr71.dll and msvcrt.dll in the
103 same process. One option is to download the source code for the libraries
104 (available from http://gnuwin32.sourceforge.net) recompile them with
105 VC++ 7.l. Then all the components will use msvcr71.dll. Once you are
106 going to go this route, you can also use static multi-threaded libraries
107 and use static linking between rrdtool (or RRDs.dll) and its dependencies.
108
109 To use the GnuWin32 library binaries, you need to trick VC++ 7.1 into
110 compiling rrdtool to use the older msvcrt.dll. Follow steps (1) - (3)
111 as above, then:
112 (4) Obtain a different version of the msvcrt.lib import library that
113 is compatible with vc7 and points to msvcrt.dll:
114 msvcrtlib_for_vc7.zip from http://xchat.org/win32/testing
115 Backup msvcrt.lib in your vc7\lib directory 
116 (\Program Files\Microsoft Visual Studio .NET 2003\vc7\lib)
117 Then extract the msvcrt.lib from the zip file into the vc7\lib directory.
118 WARNING: Use this msvcrt.lib at your own risk! This is not a Microsoft
119 supplied file nor a file supported by anyone associated with rrdtool.
120 (5) Start Microsoft Visual C++ 7.1. Load the solution file, rrdtool.sln,
121 from the src subdirectory of your rrdtool code directory. Edit zconf.h,
122 as needed, as described under (5) above. Compile the release build of
123 the rrdtool project.
124 Proceed with steps (6) - (9) as above, if you are using/picking up
125 the wrong msvcrt.lib import library then nmake test for perl-shared
126 will fail.
127
128 Note: it is possible in the future that GnuWin32 will provide Win32
129 binaries that utilize msvcr71.dll rather than msvcrt.dll.
130
131 5/14/02 Jake Brutlag
132
133 These notes share some insight I gained compiling 1.1.x with
134 MS Visual C++ 6.0 (using project files). This information may or
135 may not be accurate at the time you are reading this.
136
137 (1) freetype and rrdtool cannot use precompiled headers (which are
138 enabled by default for MSVC++ projects).  MSVC++ 6.0 does not
139 support precompiled headers if #include directives contain MACROS.
140 (2) Compile Release build with Default optimization, not the
141 Maximize Speed optimization. I encountered some strange errors
142 (related to argument processing for complex commands like graph--
143 perhaps the getopt stuff is too blame) with Maximize Speed.
144 (3) libart relies upon config.h (ostensibly generated by the
145 configure script-- but of course not on Win32 platforms). ..\..\confignt
146 (which contains a static Win32 version of config.h) should be on
147 the include path.
148 (4) Fonts are located in the %windir%\fonts, so the default font
149 is c:\winnt\fonts\cour.ttf. (6/19/02) At Kerry Calvert's suggestion
150 this setting was moved to confignt\config.h.
151 (5) libart requires a custom build step to generate art_config.h; this
152 is done manually via the commands:
153 cl -I..\..\confignt gen_art_config.c
154 gen_art_config.exe > art_config.h
155
156 Currently, to compile rrd.lib and rrdtool.exe using
157 the MSVC++ project files, first start MSVC++ 6.0. Open the rrdtool
158 workspace (rrdtool.dsw in the src directory). The active project/
159 configuration should be rrdtool-Win32 Release. Select Rebuild All
160 from the Build menu. The static link library (rrd.lib) will
161 be generated in src\release directory and executable will be generated
162 in the src\toolrelease directory.
163
164 Compiling RRDtool on NT ... work in progress
165 ---------------------------------------------------------------
166                          by Tamas Kovacshazy (khazy@mit.bme.hu)
167
168 Persisting Problems with the current NT port:
169
170 Unfortunately, the RRD perl modules does not work with Perl
171 (ActivePerl) using the current distribution.
172
173 The RRD shared perl module can be compiled after some
174 modification...
175
176 Follow these steps:
177
178 0. Install perl if you do not have it!
179    Visit http://www.ActiveState.com/pw32/ for a complete distribution.
180
181 1. Copy ..\gd1.2\release\gd.lib  to ..\gd1.2\
182 2. Copy ..\src\release\rrd.lib to ..\src
183 3. perl Makefile.pl
184
185 In this step the system complains about something I do not
186 understand. The error message is the following:
187
188 Note (probably harmless): No library found for '-lm'
189
190 Is a library missing? But it does not stop with an error...
191
192 4. nmake test (You must have Visual C++ on the machine!)
193
194 After these steps it generates the test files (svgs and rrds),
195 and they seem to be good.
196
197 The real problem in the shared perl modul is the following:
198
199 I do not know how this installation stuff works. The problem is
200 that the installation stuff looks for the gd.lib and the
201 rrd.lib in the ..\gd1.2 and ..\src directory. The UNIX compile
202 puts the files into these directories, but the NT compile does
203 not.
204
205 It is all for today,
206
207 khazy
208
209 Tamas Kovacshazy  E-mail: khazy@mit.bme.hu  
210 WWW: http://www.mit.bme.hu/~khazy
211 Technical University of Budapest 
212 Department of Measurement and Information Systems