User:Barre/Development/GCC/Static Build

From KitwarePublic
< User:Barre
Revision as of 20:08, 8 March 2005 by Barre (talk | contribs) (How to build a static release of a given software)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Here is how to build a static release of a given software with GCC.

First you need to build a specific release of the GCC compiler. Let's assume we are going to use GCC 3.4.3 (you mileage may vary, replace 3.4.3 with your favorite version):

 gcc-core-x-y-z.tar.bz2
 gcc-g++-x-y-z.tar.gz
  • Create a distribution directory for GCC:
 mkdir /opt/gcc-3.4.3s
  • Create a src directory inside the distribution directory:
 cd /opt/gcc-3.4.3s
 mkdir src
  • Unpack the GCC packages inside the src directory:
 cd src
 tar xvjf gcc-core-3.4.3.tar.bz2
 tar xvjf gcc-g++-3.4.3.tar.bz2
  • Create the below small configuration script myconfig-gcc-343 inside the src directory (note the --disable-shared option):
 #!/bin/sh
 ../gcc-3.4.3/configure \
   --prefix=/opt/gcc-3.4.3s \
   --enable-languages=c,c++ \
   --disable-shared 
  • Create a build directory inside the src directory:
 mkdir gcc-3.4.3-build
  • At this point, the distribution tree should pretty much look this way:
 /opt/gcc-3.4.3s/
 /opt/gcc-3.4.3s/src/
 /opt/gcc-3.4.3s/src/gcc-3.4.3/
 /opt/gcc-3.4.3s/src/gcc-3.4.3-build/
 /opt/gcc-3.4.3s/src/myconfig-gcc-343
  • Execute the configuration script from the build directory:
 cd gcc-3.4.3-build
 sh ../myconfig-gcc-343
  • Build the compiler from the build directory and install it:
 make
 make install
  • [OPTIONAL] Create some symlinks to this GCC build in /usr/local/bin:
 cd /usr/local/bin
 ln -s /opt/gcc-3.4.3s/bin/gcc gcc-3.4.3s
 ln -s /opt/gcc-3.4.3s/bin/g++ g++-3.4.3s
 ln -s /opt/gcc-3.4.3s/bin/c++ c++-3.4.3s
 ln -s /opt/gcc-3.4.3s/bin/cpp cpp-3.4.3s

Now re-build your software. Whatever tool you were using to build your software (for example, [http://www.cmake.org CMake), you need to point this tool to your brand-new GCC build. Most of the times, setting the CXX and CC environment variables to the path to the corresponding GCC binaries will do the trick:

 CXX=g++-3.4.3s CC=gcc-3.4.3s cmake

Do not forget to pass the -static parameter to your linker. With CMake, set:

 CMAKE_EXE_LINKER_FLAGS=-static