~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to README.minGW

  • Committer: Stefano Rivera
  • Date: 2010-07-24 15:35:51 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: stefanor@ubuntu.com-20100724153551-6s3fth1653huk31a
Tags: upstream-3.13.1
ImportĀ upstreamĀ versionĀ 3.31.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
FreeImage and MinGW / LCC WIN 32
2
 
================================
3
 
 
4
 
This file explains how to create a FreeImage.a file from the FreeImage DLL, so that it can be linked with the MinGW / LCC WIN 32 / GNU gcc C compiler.
5
 
 
6
 
1) Open a DOS shell (run the program cmd.exe)
7
 
 
8
 
2) Add the MinGW path to your environment variable : 
9
 
 
10
 
C:\>set PATH=%PATH%;C:\mingw32\bin;
11
 
 
12
 
3) Creates a .def file from the FreeImage DLL
13
 
 
14
 
C:\>pexports freeimage.dll | sed "s/^_//" > freeimage_gcc.def
15
 
 
16
 
4) Creates the FreeImage.a file
17
 
 
18
 
C:\>dlltool -U -d freeimage_gcc.def -l freeimage.a 
19
 
 
20
 
Note : you may also use a batch file to automate this process : 
21
 
 
22
 
--- FIExport.bat ---
23
 
set PATH=%PATH%;C:\mingw32\bin;
24
 
pexports freeimage.dll | sed "s/^_//" > freeimage_gcc.def
25
 
dlltool -U -d freeimage_gcc.def -l libfreeimage.a 
26
 
--- FIExport.bat ---
27
 
 
28
 
 
29
 
Here are some links on the use of WIN32 DLL with the GNU C compiler : 
30
 
=====================================================================
31
 
 
32
 
==> About pexport
33
 
 
34
 
A Moron's Guide to Using Microsoft DLL's when Compiling Cygwin or Mingw Programs
35
 
http://www.emmestech.com/software/cygwin/pexports-0.43/moron1.html
36
 
 
37
 
==> About GNU tools and DLL 
38
 
 
39
 
Introduction to (mostly) GNU Programming Tools
40
 
http://webclub.kcom.ne.jp/ma/colinp/win32/tools/index.html
41
 
 
42
 
These pages are dealing with the use of Win32 DLL :
43
 
 
44
 
The DLL Import Library Tool
45
 
http://webclub.kcom.ne.jp/ma/colinp/win32/tools/dlltool.html
46
 
 
47
 
Using Dynamic Link Libraries
48
 
http://webclub.kcom.ne.jp/ma/colinp/win32/dll/use.html
49
 
 
 
1
=====================================================================
 
2
Using the FreeImage library with the MinGW Compiler Suite
 
3
=====================================================================
 
4
 
 
5
This file describes how to use the precompiled FreeImage library
 
6
FreeImage.dll with the MinGW port of the GNU Compiler Collection
 
7
(GCC), how to build this library from source using MinGW and how
 
8
to use this MinGW-built library with Microsoft Visual Studio.
 
9
 
 
10
Contents:
 
11
 
 
12
I. Prerequisites
 
13
 
 
14
1. Using the precompiled FreeImage library with MinGW
 
15
 
 
16
2. Building the FreeImage library with MinGW
 
17
 
 
18
3. Using the MinGW FreeImage library with Microsoft Visual Studio
 
19
 
 
20
4. Useful links
 
21
 
 
22
 
 
23
---------------------------------------------------------------------
 
24
I. Prerequisites
 
25
=====================================================================
 
26
 
 
27
The procedures described in this document have been developed and
 
28
tested using the following free tools:
 
29
 
 
30
1. MinGW GCC Version 4.4.0 (Core and C++ including required libs)
 
31
2. MinGW GNU Binutils Version 2.19.1
 
32
3. MinGW GNU Make Version 3.81-20080326-3
 
33
4. MinGW Runtime Version 3.15.2
 
34
5. MinGW API for MS-Windows Version 3.13
 
35
6. GnuWin32 Package CoreUtils Version 5.3.0 (only for building)
 
36
7. GnuWin32 Package Sed Version 4.2 (only for creating the GCC
 
37
   import library)*
 
38
 
 
39
* Sed is only needed to create a GCC-native import library from
 
40
  the MSVC import library FreeImage.lib. However, since MinGW now
 
41
  supports linking against MSVC lib files, this process seems to
 
42
  be obsolete. See section 1.
 
43
 
 
44
Basically, no version dependent capabilities are used so, this
 
45
should also work with older versions of the tools mentioned above.
 
46
Similarly, the GnuWin32 packages (which I just prefer over MSYS)
 
47
could likely be replaced by a properly installed MSYS environment.
 
48
 
 
49
Furthermore, the following preconditions should be met:
 
50
 
 
51
1. The folders 'bin' under both the MinGW and the GnuWin32
 
52
   installation directory should have been added to the PATH
 
53
   environment variable. Likely it is best adding these
 
54
   directories permanently to PATH through the System
 
55
   Properties dialog on the Control Panel.
 
56
 
 
57
2. The MinGW Make package only provides a 'mingw32-make.exe'
 
58
   executable. There is no alias 'make.exe'. However, make is
 
59
   preconfigured to use 'make' as the default $(MAKE) command.
 
60
   This seems to be a bug in the MinGW GNU Make distribution.
 
61
   Thus, a copy of 'mingw32-make.exe' named 'make.exe' should
 
62
   be placed into MinGW's 'bin' directory.
 
63
 
 
64
 
 
65
 
 
66
---------------------------------------------------------------------
 
67
1. Using the precompiled FreeImage library with MinGW
 
68
=====================================================================
 
69
 
 
70
When using functions from C/C++, that reside in a DLL, the linker
 
71
needs a so called import library, which specifies, how to
 
72
dynamically link these external functions during runtime. However,
 
73
different linkers use different types or formats of these import
 
74
libraries.
 
75
 
 
76
Since the precompiled FreeImage library was build with Microsoft
 
77
Visual Studio, in the past, some extra work was required to use it
 
78
from MinGW. An import library, that was compatible with GNU ld,
 
79
must have been created first.
 
80
 
 
81
However, for several MinGW versions, the GNU linker ld also
 
82
supports linking against Microsoft Visual C++ import libraries
 
83
directly. So, this effectively makes any circulating HOWTO's on
 
84
how to create a GCC-compatible import library from a MSVC lib file
 
85
more or less obsolete. Additionally, MinGW does not require the
 
86
GCC/Linux usual lib prefix for libraries, so linking with MinGW
 
87
against the precompiled FreeImage DLL is as easy as with MSVC:
 
88
 
 
89
1.) Open a DOS shell (run application cmd.exe)
 
90
 
 
91
2.) Ensure, that the 'bin' folder of MinGW is added to the PATH
 
92
    environment variable (see Prerequisites).
 
93
 
 
94
3.) Link directly against the supplied lib file:
 
95
 
 
96
    C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lFreeImage
 
97
 
 
98
Nonetheless, for the sake of completeness, the following steps
 
99
describe how to create a native GCC import library:
 
100
 
 
101
1.) Open a DOS shell (run application cmd.exe)
 
102
 
 
103
2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are
 
104
    added to the PATH environment variable (see Prerequisites).
 
105
 
 
106
3.) Create a .def file 'libfreeimage.def', that contains all symbols
 
107
    exported by the FreeImage library:
 
108
 
 
109
    C:\>pexports FreeImage.dll | sed "s/^_//" > libfreeimage.def
 
110
 
 
111
4.) Create the GCC compatible import library 'libfreeimage.a':
 
112
 
 
113
    C:\>dlltool --add-underscore -d libfreeimage.def -l libfreeimage.a
 
114
 
 
115
5.) Use this library to link against with GCC:
 
116
 
 
117
    C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lfreeimage
 
118
 
 
119
 
 
120
 
 
121
---------------------------------------------------------------------
 
122
2. Building the FreeImage library with MinGW
 
123
=====================================================================
 
124
 
 
125
You *do not* need to have any other third party library (like
 
126
libjpeg, libpng, libtiff, libmng and zlib and others) installed on
 
127
your system in order to compile and use the library. FreeImage uses
 
128
its own versions of these libraries. This way, you can be sure that
 
129
FreeImage will always use the latest and properly tested versions
 
130
of of these third party libraries.
 
131
 
 
132
In order to build the FreeImage library under Windows with MinGW
 
133
(GCC), ensure that all the prerequisites mentioned above are met.
 
134
The MinGW makefile aims to build a Windows DLL, that differs as
 
135
least as possible from the precompiled library that comes with the
 
136
FreeImage distribution. Thus, the build process also includes the
 
137
DLL version resource as well as the __stdcall attribute for all the
 
138
exported functions, including the MSVC-like function decorations
 
139
_FuncName@nn.
 
140
 
 
141
When building the FreeImage DLL, of course, an import library is
 
142
generated, too. However, this input library is not in GCC's native
 
143
format, but in MSVC lib format, which makes it usable from both
 
144
MinGW and Microsoft Visual Studio with no further processing.
 
145
 
 
146
The MinGW makefile can also be used to build a static library.
 
147
However, due to the different function export attributes needed
 
148
for both the dynamic and the shared library (DLL), this requires
 
149
a separate invocation of make, which in turn needs to rebuild every
 
150
source file after switching from dynamic to static and vice versa.
 
151
So, a 'make clean' is required each time, the library type is
 
152
changed.
 
153
 
 
154
The type of library to build is specified by a variable named
 
155
FREEIMAGE_LIBRARY_TYPE, which may either be set directly in the
 
156
Makefile.mingw near line 18 or may be specified as an environment
 
157
variable. This variable may either take SHARED or STATIC to build
 
158
a dynamic link library (DLL) or a static library respectively.
 
159
Since this value is used to dynamically form the actual make target
 
160
internally, only uppercase values are valid. Defaults to SHARED.
 
161
 
 
162
The MinGW makefile also supports the 'install' target. However,
 
163
this only copies the FreeImage dynamic link library (DLL) from the
 
164
Dist folder into the %SystemRoot%\system32 folder. So, invoking this
 
165
target only makes sense, if the DLL has been built before.
 
166
 
 
167
Since there is neither a common system wide 'include' nor a 'lib'
 
168
directory available under Windows, the FreeImage header file
 
169
FreeImage.h as well as both the static library and the DLL import
 
170
library FreeImage.lib just remain in the 'Dist' folder.
 
171
 
 
172
The following procedure creates the FreeImage dynamic link library
 
173
(DLL) from the sources, installs it and also creates a static
 
174
FreeImage library:
 
175
 
 
176
1.) Open a DOS shell (run application cmd.exe)
 
177
 
 
178
2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are
 
179
    added to the PATH environment variable (see Prerequisites).
 
180
 
 
181
3.) Create the FreeImage dynamic link library (DLL):
 
182
 
 
183
    C:\>make
 
184
 
 
185
4.) Install the FreeImage dynamic link library (DLL):
 
186
 
 
187
    C:\>make install
 
188
 
 
189
5.) Clean all files produced by the recent build process:
 
190
 
 
191
    C:\>make clean
 
192
 
 
193
6.) Create a static FreeImage library:
 
194
 
 
195
    C:\>set FREEIMAGE_LIBRARY_TYPE=STATIC
 
196
    C:\>make
 
197
 
 
198
You should be able to link progams with the -lFreeImage option
 
199
after the shared library is compiled and installed. You can also
 
200
link statically against FreeImage.a from MinGW.
 
201
 
 
202
 
 
203
 
 
204
---------------------------------------------------------------------
 
205
3. Using the MinGW FreeImage library with Microsoft Visual Studio
 
206
=====================================================================
 
207
 
 
208
Since the MinGW makefile creates an import library in MSVC's lib
 
209
format, the produced shared library (DLL) can be used from both
 
210
MinGW and Microsoft Visual Studio with no further adaption. Just
 
211
link to the import library FreeImage.lib from either MinGW or
 
212
Microsoft Visual Studio.
 
213
 
 
214
 
 
215
 
 
216
---------------------------------------------------------------------
 
217
4. Useful links
 
218
=====================================================================
 
219
 
 
220
- The MinGW homepage:
 
221
     http://www.mingw.org/
 
222
 
 
223
- The GnuWin32 homepage:
 
224
     http://gnuwin32.sourceforge.net/
 
225
 
 
226
- The GCC homepage and online documentation:
 
227
     http://gcc.gnu.org/
 
228
     http://gcc.gnu.org/onlinedocs/
 
229
 
 
230
- The GNU Binutils homepage and online documentation:
 
231
     http://www.gnu.org/software/binutils/
 
232
     http://sourceware.org/binutils/docs-2.19/
 
233
 
 
234
- The GNU Make homepage and online documentation:
 
235
     http://www.gnu.org/software/make/
 
236
     http://www.gnu.org/software/make/manual/make.html