This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem in Install gcc on Windows XP

Dash, Santos Kumar  IN BLR SISL wrote:
> Hi, 
> I want to Compile and install gcc on Windows XP. 
> Can you please tell me wat are the seqence of steps to do it. 
> Regards, 
> Santos Kumar Dash
> S I E M E N S Information Systems Ltd (SISL) 
> Work: -+91 -80- 28091562 (Dir)  ext: 4562
>  Cell: -+91 9886817129 

I've written a mini-howto, containing instructions on how to build the
latest gcc (currently v.4.1.1) from scratch under win32, using the
msys/mingw environment.

Readme.1st: apologize my imperfect english :/

I   - Setting up the MSYS envirnoment
II  - Installing pre-built gcc binaries
III - Creating the gcc host environment
IV  - Building and installing gcc
V   - Adding other build tools
VI  - Have fun

The first thing we'll need is a fully functional msys environment. You can
do this quickly by just downloading and installing the msys binaries
package, available at

msys 1.0.10:

To keep a clean understanding, I'll assume you installed msys in the c:\
This way, msys is located at: c:\msys

Now that msys is already installed, we need some version of gcc itself in
order we can build the latest version. This way, download the following
binary packages:

from GNUWin32 project:

from MinGW project:

To install its, create a new directory called 'gcc' or any other you want in
the c:\ root. Then extract all files above inside this new directory.
However, for libiconv and libintl, only extract the dlls inside the
package's ./bin subdir and copy its to the c:\gcc\bin directory.

Important: after extraction, go to c:\gcc\bin and delete m4.exe (msys uses a
specific m4 build, included with msys package).

After this, add the c:\gcc\bin directory to the PATH environment variable.

Notice that gcc-g++ package is not used here, because is not necessary a c++
compiler to build gcc.

You can check if it's all right by opening msys, then typing:
# gcc -v
This should show some info about the pre-built gcc.
If working, we can go to the next step.

In order to build gcc, we need setup a host directory that will receive the
new gcc binaries and files.
This should be done before the build itself, because this host directory and
files are used during the build process.

Supposing you installed msys and the pre-built gcc under c:\, you have now
the following directory structure:

 |---gcc		<- here you installed the pre-built gcc
 |---msys		<- msys environment is installed here
 |    |---bin
 |    |---doc
 |    |---etc
 |    |---home
 |    |---mingw		<- built gcc will be installed here

Now, you'll create the host environment that will receive the new gcc build
To do this, you need install the mingw-runtime, binutils and win32 api. Just
extract the mingw-runtime and w32api packages and extract its into the
c:\msys\mingw folder. For binutils, you can either, use the binutils
binaries already downloaded or build it youself.
For the first option, just extract the binutils binary package into the
c:\msys\mingw folder.
If you want to build your own binutils binaries, please read in the next
chapter about how to do this.

In msys environment, create a work directory, where the sources and
temporary build files will be placed:
# cd /
# mkdir gcc-work && cd gcc-work
# mkdir {build,source}

*** Building binutils
If you want to build binutils from source, here are the instructions.
Otherwise, jump this section.
Download the source package:
binutils 2.17:

copy/move it to the source folder (in the work directory - /gcc-work/source)
extract it:
# cd source
# tar jxf binutils-2.17.tar.bz2

go to the build directory and create a temporary directory where binutils
will be built:
# cd ../build
# mkdir binutils
# cd binutils

configure, compile and install binutils in the /mingw directory:
# ../../source/binutils-2.17/configure --prefix=/mingw --host=mingw32
--target=mingw32 --program-prefix=""
--with-gcc --with-gnu-as --with-gnu-ld --disable-nls --disable-shared
# make  CFLAGS="-O2 -D__USE_CRTIMP -fno-exceptions" LDFLAGS=-s

flags are self-explanatory, but you can get info about configuration flags
by running the configure --help command, but is important to pay attention
in the --with-lib-path flag. it determinate where utils such ld will find
for libraries. as we are installing under /mingw directory, the first 2
paths must point to this prefix. if you want to change the prefix for some
reason, do not forgot to change this! other paths are required when
searching for libs into the msys environment (if you plan to use msys

this is a time to a coffe or a beer... :)
the build process will take several minutes.

after this, just install it as the usual:
# make install

*** Building gcc
The most wanted moment has come: the gcc build itself. don't worry, nothing
surreal or cabalistic here. :)
First, download the gcc source packages - here, only c and c++ languages
will be installed, but you can obviously download other packages and modify
the command lines if you want to install other languages, such ada and java.
read about gcc configuration flags at:


copy/move its to the source directory, then extract:
# cd /gcc-work/source
# tar jxf gcc-core-4.1.1.tar.bz2
# tar jxf gcc-g++-4.1.1.tar.bz2

go to the build directory and create a temporary directory where gcc will be
# cd ../build
# mkdir gcc
# cd gcc

# ../../source/gcc-4.1.1/configure --prefix=/mingw --host=mingw32
--target=mingw32 --program-prefix="" --with-as=/mingw/bin/as.exe
--with-ld=/mingw/bin/ld.exe --with-gcc --with-gnu-ld --with-gnu-as
--enable-threads --disable-nls --enable-languages=c,c++
--disable-win32-registry --disable-shared --without-x --enable-interpreter
--enable-hash-synchronization --enable-libstdcxx-debug
# make CFLAGS="-O2 -fomit-frame-pointer" CXXFLAGS="-mthreads
-fno-omit-frame-pointer -O2" LDFLAGS=-s bootstrap2
the bootstrap process is recommended in the gcc documentation, and will
produce a compiler more optimized than other that was not built in this way.
during the bootstrap, a compiler will be generated, that will compile
another compiler, that will compile another compiler and so on. the
bootstrap2 command instructs to generate 2 pre-compilers before the final
obviously this process consumes much more build time, but the final result
is better. you can supress the bootstrap2 target in the make line, if you
don't want a bootstrapped compiler.

now, relax. drink a coffe, or lots of. this operation will take some long
time to complete.
after this, the happiness is complete: install your brand new gcc :)
# make install

your fresh new gcc build is now installed and ready to use. you can then
delete the work directory, as well the pre-built gcc directory. don't forgot
to add to the PATH variable the new gcc's bin directory.

Now that the new gcc binaries are already installed, we can add other
development tools to the gcc box. here, presenting gdb and make.

- installing gdb:
download the precompiled binaries of gdb:
gdb 6.3-2:
install the package in the c:\msys\mingw directory

i have built gdb 6.5 with success, however it does not have native support
for the pe executables. this way, the best alternative is to install the
binary package above.

- installing make:
notice that 'make' is already included with the msys package. however, if
you do not plain to work with msys later but want to use makefiles, you need
your own make binary.
you can install the precompiled binary package by extracting the following
package into the c:\msys\mingw folder:

or build it youself. to do this, download the source package:
make 3.81 source:
copy it to the source folder in msys, then extract it:
# cd /gcc-work/source
# tar jxf make-3.81.tar.bz2

go to the /gcc-work/build and create a make's build directory:
# cd ../build && mkdir make
# cd make

build and install it:
# ../../source/make-3.81/configure --prefix=/mingw --target=mingw32
--program-prefix="" --disable-nls --disable-dependency-tracking
# make CFLAGS=-O2 LDFLAGS=-s
# make install

As the title says, have fun with your latest version of gcc under win32!
Builds made with success in WinXP and Win2000, but these instructions should
work in other Win32  systems, such Win98/ME/NT/2003/Vista.
Recent snapshots for gcc 4.1 were built with success using the same approach
and steps.

Marcelo A B Slomp
View this message in context:
Sent from the gcc - Help forum at

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]