nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | Tor Lillqvist <tml@iki.fi> |
2 | Hans Breuer <hans@breuer.org> |
||
3 | |||
4 | Note that this document is not really maintained in a serious |
||
5 | fashion. Lots of information here might be misleading or outdated. You |
||
6 | have been warned. |
||
7 | |||
8 | The general parts, and the section about gcc and autoconfiscated |
||
9 | build, and about a Visual Studio build are by Tor Lillqvist. The |
||
10 | sections about MSVC build with NMAKE is by Hans Breuer. |
||
11 | |||
12 | General |
||
13 | ======= |
||
14 | |||
15 | For prebuilt binaries (DLLs and EXEs) and developer packages (headers, |
||
16 | import libraries) of GLib, Pango, GTK+ etc for Windows, go to |
||
17 | http://www.gtk.org/download-windows.html . They are for "native" |
||
18 | Windows meaning they use the Win32 API and Microsoft C runtime library |
||
19 | only. No POSIX (Unix) emulation layer like Cygwin in involved. |
||
20 | |||
21 | To build GLib on Win32, you can use either gcc ("mingw") or the |
||
22 | Microsoft compiler and tools. For the latter, MSVC6 and later have |
||
23 | been used successfully. Also the Digital Mars C/C++ compiler has |
||
24 | reportedly been used. |
||
25 | |||
26 | You can also cross-compile GLib for Windows from Linux using the |
||
27 | cross-compiling mingw packages for your distro. |
||
28 | |||
29 | Note that to just *use* GLib on Windows, there is no need to build it |
||
30 | yourself. |
||
31 | |||
32 | On Windows setting up a correct build environment can be quite a task, |
||
33 | especially if you are used to just type "./configure; make" on Linux, |
||
34 | and expect things to work as smoothly on Windows. |
||
35 | |||
36 | The following preprocessor macros are to be used for conditional |
||
37 | compilation related to Win32 in GLib-using code: |
||
38 | |||
39 | - G_OS_WIN32 is defined when compiling for native Win32, without |
||
40 | any POSIX emulation, other than to the extent provided by the |
||
41 | bundled Microsoft C library (msvcr*.dll). |
||
42 | |||
43 | - G_WITH_CYGWIN is defined if compiling for the Cygwin |
||
44 | environment. Note that G_OS_WIN32 is *not* defined in that case, as |
||
45 | Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined by a GLib |
||
46 | for Cygwin. |
||
47 | |||
48 | - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN |
||
49 | is defined. |
||
50 | |||
51 | These macros are defined in glibconfig.h, and are thus available in |
||
52 | all source files that include <glib.h>. |
||
53 | |||
54 | Additionally, there are the compiler-specific macros: |
||
55 | - __GNUC__ is defined when using gcc |
||
56 | - _MSC_VER is defined when using the Microsoft compiler |
||
57 | - __DMC__ is defined when using the Digital Mars C/C++ compiler |
||
58 | |||
59 | G_OS_WIN32 implies using the Microsoft C runtime, normally |
||
60 | msvcrt.dll. GLib is not known to work with the older crtdll.dll |
||
61 | runtime, or the static Microsoft C runtime libraries libc.lib and |
||
62 | libcmt.lib. It apparently does work with the debugging version of |
||
63 | msvcrt.dll, msvcrtd.dll. If compiled with Microsoft compilers newer |
||
64 | than MSVC6, it also works with their compiler-specific runtimes, like |
||
65 | msvcr70.dll or msvcr80.dll. Please note that it's non totally clear if |
||
66 | you would be allowed by the license to distrubute a GLib linked to |
||
67 | msvcr70.dll or msvcr80.dll, as those are not part of the operating |
||
68 | system, but of the MSVC product. msvcrt.dll is part of Windows. |
||
69 | |||
70 | For people using Visual Studio 2005 or later: |
||
71 | |||
72 | If you are building GLib-based libraries or applications, or GLib itself |
||
73 | and you see a C4819 error (or warning, before C4819 is treated as an error |
||
74 | in msvc_recommended_pragmas.h), please be advised that this error/warning should |
||
75 | not be disregarded, as this likely means portions of the build is not being |
||
76 | done correctly, as this is an issue of Visual Studio running on CJK (East Asian) |
||
77 | locales. This is an issue that also affects builds of other projects, such as |
||
78 | QT, Firefox, LibreOffice/OpenOffice, Pango and GTK+, along with many other projects. |
||
79 | |||
80 | To overcome this problem, please set your system's locale setting for non-Unicode to |
||
81 | English (United States), reboot, and restart the build, and the code should build |
||
82 | normally. See also this GNOME Wiki page [1] that gives a bit further info on this. |
||
83 | |||
84 | Building software that use GLib or GTK+ |
||
85 | ======================================= |
||
86 | |||
87 | Building software that just *uses* GLib or GTK+ also require to have |
||
88 | the right compiler set up the right way. If you intend to use gcc, |
||
89 | follow the relevant instructions below in that case, too. |
||
90 | |||
91 | Tor uses gcc with the -mms-bitfields flag which means that in order to |
||
92 | use the prebuilt DLLs (especially of GTK+), if you compile your code |
||
93 | with gcc, you *must* also use that flag. This flag means that the |
||
94 | struct layout rules are identical to those used by MSVC. This is |
||
95 | essential if the same DLLs are to be usable both from gcc- and |
||
96 | MSVC-compiled code. Such compatibility is desirable. |
||
97 | |||
98 | When using the prebuilt GLib DLLs that use msvcrt.dll from code that |
||
99 | uses other C runtimes like for example msvcr70.dll, one should note |
||
100 | that one cannot use such GLib API that take or returns file |
||
101 | descriptors. On Windows, a file descriptor (the small integer as |
||
102 | returned by open() and handled by related functions, and included in |
||
103 | the FILE struct) is an index into a table local to the C runtime |
||
104 | DLL. A file descriptor in one C runtime DLL does not have the same |
||
105 | meaning in another C runtime DLL. |
||
106 | |||
107 | Building GLib |
||
108 | ============= |
||
109 | |||
110 | Again, first decide whether you really want to do this. |
||
111 | |||
112 | Before building GLib you must also have a GNU gettext-runtime |
||
113 | developer package. Get prebuilt binaries of gettext-runtime from |
||
114 | http://www.gtk.org/download-windows.html . |
||
115 | |||
116 | Autoconfiscated build (with gcc) |
||
117 | ================================ |
||
118 | |||
119 | Tor uses gcc 3.4.5 and the rest of the mingw utilities, including MSYS |
||
120 | from www.mingw.org. Somewhat earlier or later versions of gcc |
||
121 | presumably also work fine. |
||
122 | |||
123 | Using Cygwin's gcc with the -mno-cygwin switch is not recommended. In |
||
124 | theory it should work, but Tor hasn't tested that lately. It can |
||
125 | easily lead to confusing situations where one mixes headers for Cygwin |
||
126 | from /usr/include with the headers for native software one really |
||
127 | should use. Ditto for libraries. |
||
128 | |||
129 | If you want to use mingw's gcc, install gcc, win32api, binutils and |
||
130 | MSYS from www.mingw.org. |
||
131 | |||
132 | Tor invokes configure using: |
||
133 | |||
134 | CC='gcc -mtune=pentium3 -mthreads' CPPFLAGS='-I/opt/gnu/include' \ |
||
135 | LDFLAGS='-L/opt/gnu/lib -Wl,--enable-auto-image-base' CFLAGS=-O2 \ |
||
136 | ./configure --disable-gtk-doc --prefix=$TARGET |
||
137 | |||
138 | The /opt/gnu mentioned contains the header files for GNU and (import) |
||
139 | libraries for GNU libintl. The build scripts used to produce the |
||
140 | prebuilt binaries are included in the "dev" packages. |
||
141 | |||
142 | Please note that the ./configure mechanism should not blindly be used |
||
143 | to build a GLib to be distributed to other developers because it |
||
144 | produces a compiler-dependent glibconfig.h. For instance, the typedef |
||
145 | for gint64 is long long with gcc, but __int64 with MSVC. |
||
146 | |||
147 | Except for this and a few other minor issues, there shouldn't be any |
||
148 | reason to distribute separate GLib headers and DLLs for gcc and MSVC6 |
||
149 | users, as the compilers generate code that uses the same C runtime |
||
150 | library. |
||
151 | |||
152 | The DLL generated by either compiler is binary compatible with the |
||
153 | other one. Thus one either has to manually edit glibconfig.h |
||
154 | afterwards, or use the supplied glibconfig.h.win32 which has been |
||
155 | produced by running configure twice, once using gcc and once using |
||
156 | MSVC, and merging the resulting files with diff -D. |
||
157 | |||
158 | For MSVC7 and later (Visual C++ .NET 2003, Visual C++ 2005, Visual C++ |
||
159 | 2008 etc) it is preferred to use specific builds of GLib DLLs that use |
||
160 | the same C runtime as the code that uses GLib. Such DLLs should be |
||
161 | named differently than the ones that use msvcrt.dll. |
||
162 | |||
163 | For GLib, the DLL that uses msvcrt.dll is called libglib-2.0-0.dll, |
||
164 | and the import libraries libglib-2.0.dll.a and glib-2.0.lib. Note that |
||
165 | the "2.0" is part of the "basename" of the library, it is not |
||
166 | something that libtool has added. The -0 suffix is added by libtool |
||
167 | and is the value of "LT_CURRENT - LT_AGE". The 0 should *not* be |
||
168 | thought to be part of the version number of GLib. The LT_CURRENT - |
||
169 | LT_AGE value will on purpose be kept as zero as long as binary |
||
170 | compatibility is maintained. For the gory details, see configure.ac |
||
171 | and libtool documentation. |
||
172 | |||
173 | Building with Visual Studio |
||
174 | =========================== |
||
175 | |||
176 | A more detailed outline of building GLib with its dependencies can |
||
177 | now be found on the GNOME wiki: |
||
178 | |||
179 | https://wiki.gnome.org/Projects/GTK%2B/Win32/MSVCCompilationOfGTKStack |
||
180 | |||
181 | Please do not build GLib in paths that contain spaces in them, as |
||
182 | this may cause problems during compilation and during usage of the |
||
183 | library. |
||
184 | |||
185 | In an unpacked tarball, you will find in build\win32\vs9 (VS 2008) and |
||
186 | build\win32\vs10 (VS 2010) a solution file that can be used to build |
||
187 | the GLib DLLs and some auxiliary programs under VS 2008 and VS 2010 |
||
188 | (Express Edition will suffice with the needed dependencies) respectively. |
||
189 | Read the README.txt file in those folders for more |
||
190 | information. Note that you will need a libintl implementation, zlib, and |
||
191 | libFFI. |
||
192 | |||
193 | If you are building from a GIT checkout, you will first need to use some |
||
194 | Unix-like environment or run build/win32/setup.py, |
||
195 | which will expand the VS 2008/2010 project files, the DLL resouce files and |
||
196 | other miscellanious files required for the build. Run build/win32/setup.py |
||
197 | as follows: |
||
198 | |||
199 | $python build/win32/setup.py --perl path_to_your_perl.exe |
||
200 | |||
201 | for more usage on this script, run |
||
202 | $python build/win32/setup.py -h/--help |
||
203 | |||
204 | Building with MSVC and NMAKE |
||
205 | ============================ |
||
206 | |||
207 | If you are building from a GIT snapshot, you will not have all |
||
208 | makefile.msc files. You should copy the corresponding makefile.msc.in |
||
209 | file to that name, and replace any @...@ strings with the correct |
||
210 | value (or use the python script de-in.py from http://hans.breuer.org/gtk/de-in.py). |
||
211 | |||
212 | This is done automatically when an official GLib source distribution |
||
213 | package is built, so if you get GLib from a source distribution |
||
214 | package, there should be makefile.msc files ready to use (possibly after some |
||
215 | editing). |
||
216 | |||
217 | The hand-written makefile.msc files, and the stuff in the "build" |
||
218 | subdirectory, produce DLLs and import libraries that match what the |
||
219 | so-called autoconfiscated build produces. |
||
220 | |||
221 | All the MSVC makefiles are for the command line build with nmake. If |
||
222 | you want to use the VC-UI you can simply create wrapper .dsp makefiles |
||
223 | (read the VC docs how to do so). |
||
224 | |||
225 | Some modules may require Perl to auto-generate files. The goal (at |
||
226 | least Hans's) is to not require any more tools. Of course you need |
||
227 | the Microsoft Platform SDK in a recent enough - but not too recent - version. |
||
228 | The last PSDK for Visual Studio 6 is: |
||
229 | http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm |
||
230 | At least install the Core SDK, maybe also the "Tablet PC SDK". |
||
231 | |||
232 | |||
233 | Build with: |
||
234 | |||
235 | nmake -f makefile.msc |
||
236 | or |
||
237 | nmake -f makefile.msc DEBUG=1 |
||
238 | |||
239 | [ |
||
240 | The former will create 'release' versions of the DLLs. If you |
||
241 | plan to distribute you DLLs please use this command. The latter |
||
242 | will create DLLs with debug information _and_ link them with |
||
243 | msvcrtd.dll instead of msvcrt.dll. |
||
244 | Beware: There are known problems with mixing DLLs in one |
||
245 | application, which are build against different runtimes. |
||
246 | Especially the index-to-file mapping used by 'unix-style' file |
||
247 | operation - _open() _pipe() etc. - breaks sometimes in strange |
||
248 | ways (for example the Gimp plug-in communication). |
||
249 | ] |
||
250 | |||
251 | Required libraries (not build from svn) |
||
252 | ------------------ |
||
253 | libintl (gnu-intl), |
||
254 | |||
255 | are available pre-built from the website mentioned above. |
||
256 | |||
257 | Versioning |
||
258 | ---------- |
||
259 | Instead of the Unix and auto* way of tracking versions and resolving |
||
260 | dependencies (configure; make; make install) involving autoconf, |
||
261 | automake, libtool and friends the MSVC build uses a different |
||
262 | approach. |
||
263 | |||
264 | The core of it's versioning is the file build/win32/module.defs. |
||
265 | It contains entries of the form MODULE_VER, e.g.: |
||
266 | |||
267 | GLIB_VER = 2.0 |
||
268 | LIBICONV_VER = 1.3 |
||
269 | |||
270 | and the placement of these modules defined as MODULE, e.g.: |
||
271 | |||
272 | GLIB = $(TOP)/glib |
||
273 | LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER) |
||
274 | |||
275 | whereas TOP is defined as the relative path from the respective |
||
276 | module directory to your top build directory. Every makefile.msc |
||
277 | needs to define TOP before including the common make file part |
||
278 | make.msc, which than includes module.defs, like: |
||
279 | |||
280 | TOP = ../.. |
||
281 | !INCLUDE $(TOP)/glib/build/win32/make.msc |
||
282 | |||
283 | (Taken from gtk+/gdk/makefile.msc) |
||
284 | |||
285 | With this provision it is possible to create almost placement |
||
286 | independent makefiles without requiring to 'install' the libraries and |
||
287 | headers into a common place (as it is done on Unix, and as Tor does |
||
288 | when producing his zipfiles with prebuilt GLib, GTK+ etc). |
||
289 | |||
290 | Special Files |
||
291 | ------------- |
||
292 | config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by |
||
293 | the current version/build number. The resulting file is to be saved |
||
294 | as 'config.h.win32'. This should be automatically done if a package |
||
295 | gets build on the Unix platform. |
||
296 | |||
297 | makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as |
||
298 | makefile.msc. |
||
299 | |||
300 | <module>.def : every function which should be used from the outside of |
||
301 | a dll needs to be marked for 'export'. It is common that one needs to change |
||
302 | these files after some api changes occured. If there are variables to be |
||
303 | exported another mechanism is needed, like : |
||
304 | |||
305 | #ifdef G_OS_WIN32 |
||
306 | # ifdef GDK_COMPILATION |
||
307 | # define GDKVAR __declspec(dllexport) |
||
308 | # else |
||
309 | # define GDKVAR extern __declspec(dllimport) |
||
310 | # endif |
||
311 | #else |
||
312 | # define GDKVAR extern |
||
313 | #endif |
||
314 | |||
315 | |||
316 | |||
317 | Directory Structure |
||
318 | ------------------- |
||
319 | all modules should be build in a common directory tree otherwise you |
||
320 | need to adapt the file 'module.defs'. They are listed here in increasing |
||
321 | dependencies order. |
||
322 | |||
323 | <common rootdir without spaces> |
||
324 | | |
||
325 | +- glib |
||
326 | | | |
||
327 | | +- build : [this module lives in the SVN root dir] |
||
328 | | | +- win32 |
||
329 | | | .\module.defs : defines (relative) locations of the headers |
||
330 | | | and libs and version numbers to be include |
||
331 | | | in dll names |
||
332 | | | .\make.msc : include by almost every 'makefile.msc' |
||
333 | | | |
||
334 | | | .\README.WIN32 : more information how to build |
||
335 | | | .\glibconfig.h.win32.in : similar to config.h.win32.in |
||
336 | | | .\makefile.msc : master makefile, sub dir makefiles should work |
||
337 | | | |
||
338 | | +- glib |
||
339 | | +- gmodule |
||
340 | | +- gthread : does _not_ depend on pthread anymore |
||
341 | | +- gobject |
||
342 | | |
||
343 | +- pango |
||
344 | | +- pango : 'native' build does not require extra libs and |
||
345 | | | includes the minimal required text renderer |
||
346 | | | (there is also a currently slightly broken FreeType2 |
||
347 | | | based implementation for win32) |
||
348 | | +- modules (not yet build) |
||
349 | | |
||
350 | +- atk |
||
351 | | +- atk |
||
352 | | .\makefile.msc : build here |
||
353 | | |
||
354 | +- gtk+ |
||
355 | | | .\config.h.win32 : for all the below |
||
356 | | | |
||
357 | | +- gdk-pixbuf |
||
358 | | | .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs |
||
359 | | | to be converted (filled with version info) |
||
360 | | | as described above. |
||
361 | | | |
||
362 | | +- gdk |
||
363 | | | | .\makefile.msc : some auto-generation is needed to build in the |
||
364 | | | | in the subdirectory |
||
365 | | | +- win32 |
||
366 | | | |
||
367 | | +- gtk |
||
368 | |||
369 | | |
||
370 | +- gimp |
||
371 | | .\makefile.msc : master makefile to build The Gimp. The makefiles |
||
372 | | from the sub dirs should work stand alone, but than |
||
373 | | the user needs to know the build order |
||
374 | |||
375 | | |
||
376 | +- dia : additionally depends on libart_lgpl (in SVN) |
||
377 | | and libxml2 ( see http://www.xmlsoft.org/ ) |
||
378 | +- lib |
||
379 | +- app |
||
380 | +- objects |
||
381 | +- plug-ins |
||
382 | +- python |
||
383 | |||
384 | [1]: https://wiki.gnome.org/Projects/GTK%2B/Win32/MSVCCompilationOfGTKStack under "Preparations" |