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