1 TITLE: Linux to Windows
2 LFS VERSION: LFS CVS [20030603]
3 AUTHOR: Nathan Coulson <conathan@conet.dyndns.org>
4 Seth W. Klein <sk@sethwklein.net>
6 Ever want to compile windows programs from linux? This hint shows
7 how to build i386-pc-mingw32, i386-pc-cygwin32, and i386-pc-msdosdjgpp
12 0.1: Text has been fixed up, updated to gcc 3.3.1 Compile libraries
16 First, to cover some of the basics. To compile the libraries for
17 these compilers, you need the compilers, but to compile the compilers, you
18 need the libraries. This circular dependency is solved by starting with
19 binary versions of the libraries.
21 I am going to define some variables for use in the commands below,
22 and you may edit them as you see fit. PREFIX is the destination directory,
23 while TARGET is the type of compiler you wish to install.
25 i386-pc-mingw32 [binary libraries]
26 ==================================
27 MinGW is a collection of freely available and freely distributable
28 Windows specific header files and import libraries combined with GNU toolsets
29 that allow one to produce native Windows programs that do not rely on any
33 binutils-2.14.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils]
34 gcc-3.3.1.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc]
35 mingw-runtime-3.0.tar.bz2 [http://www.sf.net/projects/mingw]
36 w32api-2.3.tar.bz2 [http://www.sf.net/projects/mingw]
39 PREFIX=/opt/cross-compile_bin
40 TARGET=i386-pc-mingw32
41 export PATH=$PREFIX/bin:$PATH
45 These must be installed into the correct directories, so we use tar's
46 -C option to specify the destination. We also make sure that the directory
49 mkdir -p $PREFIX/$TARGET
50 tar -xjf mingw-runtime-3.0.tar.bz2 -C $PREFIX/$TARGET
51 tar -xjf w32api-2.3.tar.bz2 -C $PREFIX/$TARGET
54 And now for binutils. The only difference from the LFS instructions,
57 tar -xjf binutils-2.13.2.tar.bz2
60 ../binutils-2.13.2/configure --prefix=$PREFIX --target=$TARGET
65 We then compile GCC last, so it uses the above libraries. You may have
66 noticed the --enable-version-specific-runtime-libs, I have added that, so that
67 libraries are installed within their own seperate folder.
69 tar -xjf gcc-3.2.3.tar.bz2
72 ../gcc-3.2.3/configure --prefix=$PREFIX --target=$TARGET \
73 --enable-threads=win32 --enable-languages=c,c++ \
74 --enable-version-specific-runtime-libs
79 To use your new cross-compiler, put $PREFIX/bin first in your PATH.
80 (It will already be there if you set the variables as above.)
82 If you want to try it out, type in the following
84 echo 'main() { puts("Hello World"); }' > test.c
85 $TARGET-gcc test.c -o test.exe
87 Copy this to a windows machine (if avaliable), and run it. (It
88 should print "Hello World" to the screen before exiting).
90 MinGW does not require any addition files to run on windows.
92 i386-pc-mingw32 [compiled libraries]
93 ====================================
95 binutils-2.13.2.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils]
96 gcc-3.2.3.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc]
97 mingw-runtime-3.0-src.tar.bz2 [http://www.sf.net/projects/mingw]
98 w32api-2.3-src.tar.bz2 [http://www.sf.net/projects/mingw]
99 * Note that we use the source code of the 2 libraries this time
102 PREFIX=/opt/cross-compile
103 TARGET=i386-pc-mingw32
104 export PATH=$PREFIX/bin:$PATH
105 * We have changed the prefix to /opt/cross-compile, as to make a fresh install
106 * This path adds onto the previous path for the binary version, otherwise it
107 cannot find $TARGET-gcc.
110 Since we now have a i386-pc-mingw32 toolchain, we can install the
111 libraries. We move w32api-2.3 to w32api, because mingw-runtime searches for
112 header files in ../w32api/include. [you can watch the packages as it compiles
113 to verify this]. We install to $PREFIX/$TARGET, as the libraries do not install
114 themselves to the $TARGET directory by default, and if we installed to /usr,
115 this would overwrite our default headers. I also had to override the programs
116 that configure uses by default on mingw-runtime, for it does not appear to use
119 tar -xjf mingw-runtime-3.0-src.tar.bz2
120 tar -xjf w32api-2.3-src.tar.bz2
124 ../mingw-runtime-3.0/configure --prefix=$PREFIX/$TARGET --target=$TARGET
125 make CC="i386-pc-mingw32-gcc" DLLTOOL="i386-pc-mingw32-dlltool" \
126 AS="i386-pc-mingw32-as" AR="i386-pc-mingw32-ar" \
127 LD="i386-pc-mingw32-ld" RANLIB="i386-pc-mingw32-ranlib"
132 ../w32api/configure --prefix=$PREFIX/$TARGET --host==$TARGET
144 The compiled version should work the same way as the binary way.
146 i386-pc-cygwin32 [binary libraries] (Untested)
147 ===================================
148 Cygwin is a Linux-like environment for Windows.
151 binutils-2.13.2.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils]
152 gcc-3.2.3.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc]
153 cygwin-1.3.22-1.tar.bz2 [http://www.cygwin.com/mirrors.html]
154 w32api-2.3.tar.bz2 [http://www.sf.net/projects/mingw]
155 * I got w32api-2.3 from mingw, and just used it for cygwin. seems to work... but I
156 beleive you can also download w32api from www.cygwin.com/mirrors.html
159 PREFIX=/opt/cross-compile_bin
160 TARGET=i386-pc-cygwin32
161 export PATH=$PREFIX/bin:$PATH
164 I am not completely familiar with where libraries files go, but it
165 seems good enough to compile the next part. [If anyone has any useful
166 information, please email conathan@conet.dyndns.org].
168 mkdir -p $PREFIX/$TARGET
170 tar -xjf cygwin-1.3.22-1.tar.bz2 -C tmp
171 cp -a tmp/usr/include/* $PREFIX/$TARGET/include
172 cp -a tmp/usr/lib/* $PREFIX/$TARGET/lib
173 tar -xjf w32api-2.3.tar.bz2 -C $PREFIX/$TARGET
176 tar -xjf binutils-2.13.2.tar.bz2
179 ../binutils-2.13.2/configure --prefix=$PREFIX --target=$TARGET
184 When I checked gcc -v on cygwin, it was compiled with
185 --enable-threads=posix, so I'll use it below.
187 tar -xjf gcc-3.2.3.tar.bz2
190 ../gcc-3.2.3/configure --prefix=$PREFIX --target=$TARGET \
191 --enable-threads=posix --enable-languages=c,c++ \
192 --enable-version-specific-runtime-libs
197 To use your new cross-compiler, put $PREFIX/bin first in your PATH.
198 (It will already be there if you set the variables as above.) In
199 addition, when building a package configured with autoconf, pass
200 --host=$TARGET to the configure script.
202 If you want to try it out, type in the following
204 echo 'main() { puts("Hello World"); }' > test.c
205 $TARGET-gcc test.c -o test.exe
207 Copy this to a windows machine (if avaliable), and run it. (It
208 should print "Hello World" to the screen before exiting). Please note that
209 you require the cygwin environment for windows, downloadable at www.cygwin.com.
210 The advantage of cygwin over mingw, is that most linux programs could probably
211 be easly compiled for cygwin, although requiring the cygwin.dll to run.
213 i386-pc-cygwin32 [compiled libraries] (Untested)
214 ==============================================
216 binutils-2.13.2.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils]
217 gcc-3.2.3.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc]
218 cygwin-1.3.22-1-src.tar.bz2 [http://www.cygwin.com/mirrors.html]
219 w32api-2.3-src.tar.bz2 [http://www.sf.net/projects/mingw]
220 * again, I got w32api-2.3 from mingw, and just used it for cygwin. seems to
222 * This path adds onto the previous path for the binary version, otherwise it
223 cannot find $TARGET-gcc.
226 PREFIX=/opt/cross-compile
227 TARGET=i386-pc-cygwin32
228 export PATH=$PREFIX/bin:$PATH
231 It appears that the cygwin libraries behave better then the mingw ones
232 do, and a simple --prefix=$PREFIX should install nicely. It even uses
233 the correct programs to recompile itself. w32api is automatically compiled
234 when you add it to the winsup directory, and the cygwin sources will
235 not compile without it, afaik.
237 tar -xjf cygwin-1.3.22-1-src.tar.bz2
238 tar -xzf w32api-2.3-src.tar.gz
239 mv w32api-2.3 cygwin-1.3.22-1/winsup/w32api
243 ../cygwin-1.3.22-1/configure --prefix=/usr --target=$TARGET
247 rm -rf cygwin-1.3.22-1 cygwin-build
250 The above instructions are sufficient.
253 The above instructions are sufficient.
256 The compiled version should work the same way as the binary way
258 i386-pc-msdosdjgpp [binary libraries]
259 ==================================
261 binutils-2.13.2.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils]
262 gcc-3.2.3.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc]
263 gcc323s2.zip [http://www.delorie.com/pub/djgpp/current/v2gnu/]
264 djcrx203.zip [http://www.delorie.com/pub/djgpp/current/v2/]
265 autoconf-2.13.tar.bz [ftp://ftp.gnu.org/gnu/autoconf]
266 automake-1.5.tar.bz2 [ftp://ftp.gnu.org/gnu/automake]
269 PREFIX=/opt/cross-compile_bin
270 TARGET=i386-pc-msdosdjgpp
271 export PATH=$PREFIX/bin:$PATH
274 We use the -a on unzip, so that it automatically formats the text files
275 for linux. Compile stubify [used for GCC I believe], and then just copy over
276 the headers and libraries.
278 mkdir -p $PREFIX/$TARGET/{bin,include,lib}
281 unzip -a ../../lfs.packages/djcrx203.zip
282 cp -r include/* $PREFIX/$TARGET/include
283 cp -r lib/* $PREFIX/$TARGET/lib
285 gcc stubify.c -o $PREFIX/$TARGET/bin/stubify
291 binutils does not appear to require any libraries to compile itself, so
294 tar -xjf binutils-2.13.2.tar.bz2
297 ../binutils-2.13.2/configure --prefix=$PREFIX --target=$TARGET
302 GCC is harder to build then the above targets, as we have to patch the
303 sources first. On the http://www.delorie.com/djgpp site, you can find a
304 gcc323s.zip file, but it does not store filepermissions and therefore it is
305 easier for us to patch.
307 We require older versions of autoconf and automake to patch gcc
308 properly, as indicated on the gcc's faq. The instructions are provided below.
310 export PATH=$PREFIX/tmp/bin:$PATH
313 tar -xjf /autoconf-2.13.tar.bz2
315 ./configure --prefix=$PREFIX/tmp
320 tar -xjf ../lfs.packages/automake-1.5.tar.bz2
322 ./configure --prefix=$PREFIX/tmp
328 Now, onto patching the gcc source. Any errors
332 unzip -a ../../lfs.packages/gcc323s2.zip
333 chmod 755 unpack-gcc.sh
334 ./unpack-gcc.sh ../../lfs.packages/gcc-3.2.3.tar.gz
337 This has unarchived and patched the source to gcc/gnu/gcc3.23,
338 and we can finally compile it
343 ../gcc-3.23/configure --prefix=$PREFIX --target=$TARGET \
344 --with-headers=$PREFIX/$TARGET/include --enable-languages=c,c++ \
345 --enable-version-specific-runtime-libs
351 We do not require the autotools anymore, so...
356 To use your new cross-compiler, put $PREFIX/bin first in your PATH.
357 (It will already be there if you set the variables as above.) In addition,
358 when building a package configured with autoconf, pass --host=$TARGET to the
364 -Test Compiled Binaries, and determine requiraments to run
365 i386-pc-msdosdjgpp: (Test, Find a way to compmile the libraries [hard])
367 -Figure out how to actually run the compiled programs [listed on
368 djgpp's howto page at www.delorie.com/djgpp]
369 -Compile the libraries [looks like extracting djlsr203.zip, then
370 extract djcrx203.zip into it]
371 -check --enable-threads value
374 gcc, I noticed like to stick C++ libraries under the /include directory. I
375 dont know if that is good or not, so I used
376 --enable-version-specific-runtime-libs to counteract this. (It was probably
377 a typo, and was my fault though. I'll double check someday).