GCC HINT

Eric D Crahen crahen at cse.Buffalo.EDU
Fri Jan 18 13:29:32 PST 2002


I attached a hint for using multiple versions of gcc


- Eric
http://www.cse.buffalo.edu/~crahen
-------------- next part --------------
TITLE:		Multiple GCC Installation
LFS VERSION:	All
AUTHOR:		Eric Crahen <crahen at cse.buffalo.edu>

SYNOPSIS:
	
	This is a set of instructions for people interested in installing and
	using several versions of gcc on thier system. There are alot of reasons
	a person may want to do this. For example, you may need several versions 
	of gcc for developent, you may want to use the recommended egcs compiler 
	for kernel compilations, you may want to test out a version of gcc without 
	disrupting the current working version of gcc, you may just be curious about
	how you might do this, or you may have another reason all together.

HINT:
	
	QUICK OVERVIEW:

	Installing several versions is accomplished by keeping the runtime dependancies
	separate from one another, renaming the executables, and using environment
	variables. 


	OBTAIN THE SOURCE:


	First, you need to obtain the version of gcc you wish to compile and install
	along with any patches that come with it. In the example, I'll show two versions
	but I will point out how you can easily adapt this to any version you need to compile.
	
	EGCS-1.1.2:

	ftp://sourceware.cygnus.com/pub/gcc/old-releases/egcs/egcs-1.1.2.tar.bz2
	http://gcc.gnu.org/install/glibc-2.2.patch

	GCC-2.95.3:

	ftp://ftp.gnu.org/pub/gnu/gcc/gcc-2.95.3.tar.gz
	http://ftp.linuxfromscratch.org/lfs-packages/3.1/gcc-2.95.3-2.patch.bz2


	COMPILE THE SOURCE & INSTALL:

	
	Next you need to configure the source. This is done in the usual way, the important
	configuration options are the '--enable-version-specific-runtime-libs' and the
	'--program-transform-name' options.

	The '--enable-version-specific-runtime-libs' keeps the version specific
	runtime libraries in a compiler specific directory rather than placing them
	right in ${libdir}. 

	You can read more about this in the gcc documentation (install/CONFIGURE).

	The '--program-transform-name' transforms the binary file names when they are 
	installed using a regular expression. This transformation is based on a sed
	expression so you can change the names into anything. The recommended transformation
	is to add the version as a suffix to the binary name.	

	You can read more about this by running	configure (./configure --help).

	Example of configuring two commonly found versions of the compiler are shown
	below. You can add or remove any of the configure parameters you'd like so long
	as the aforementioned two remain present.


	ECGS-1.1.2:


	sed -e s/gcc-2.95.2/egcs-1.1.2/ glibc-2.2.patch | patch -p0; \
	mkdir egcs-build && cd egcs-build && \
	../egcs-1.1.2/configure --prefix=/usr  \
	--enable-languages --enable-languages=c,c++ \
	--enable-threads=posix \
	--enable-version-specific-runtime-libs \
	--program-transform-name="s/\\\\(.*\\\\)/\\\\1-2.91.66/" && \
	make bootstrap && make install

	
	GCC-2.95.3:

	bzip2 -dc gcc-2.95.3-2.patch.bz2 | patch -Np1; &&
	mkdir ../gcc-build && cd ../gcc-build &&
	../gcc-2.95.3/configure --prefix=/usr \
	--enable-languages --enable-languages=c,c++ \
	--enable-threads=posix \
	--enable-version-specific-runtime-libs \
	--program-transform-name="s/\\\\(.*\\\\)/\\\\1-2.95.3/" && \
	make bootstrap && make install



	SETUP YOUR ENVIRONMENT:


	Finnally, you need to setup your environment. This can vary from shell to
	shell. I will show how to do this for bash, if you need to use a different 
	shell check your man page for the correct method for exporting environment
	variables.

	CC, CXX and CPP are the standard names of the environment variables used 
	by most tools like make and autoconf. To select the compiler you want to
	use simply point these variables to the correct place.

	CC=cc-2.91.66 
	CXX=c++-2.91.66

	export CC CXX

	You can place this a system wide script such as /etc/profile or in your 
	own .bashrc.


	COMMON MISTAKES:



	1.) The '--program-transform-name' option doesn't do anything!?

	This is can be frustrating because you won't find the error until
	you have compiled and installed the source and notices the binary
	names have not changed. The reason is almost certainly because the
	regular expression has not been escaped properly. Test your expression
	with sed and quadruple the number of \'s used to escape it.

	Why? Well, suppose you want to add a suffix to a word. The following sed 
	expression does this. You need to escape special characters for sed.

	echo name | sed -e "s/\(.*\)/\1-suffix/"
	
	If you want to get that expression into a Makefile as a string that the Makefile 
	will eventually execute, you have to escape that expression (because Makefiles
	treat \'s specially).

	s/\\(.*\\)/\\1-suffix/

	So to get the string show above from a shell prompt into any program you
	have to escape it again for the shell. So you end up with,

	s/\\\\(.*\\\\)/\\\\1-suffix/

	And the configure option becomes,

	--program-transform-name="s/\\\\(.*\\\\)/\\\\1-suffix/"

	2.) cc doesn't work now!?
	
	The compiler is still there, but the name has been changed so you can
	select which one you want to use by name. You have several options.
	
	- use $(CC) instead of cc, use $(CXX) instead of c++
	- create a symlink for the version you want to default to
	  ln -s /usr/bin/gcc-2.95.3 /usr/bin/gcc
	  ln -s /usr/bin/g++-2.95.3 /usr/bin/g++

	Most people won't expirence this problem. If your environment is correctly
	configured tools like autoconf and make will detect your compile without any
	trouble.


More information about the hints mailing list