Hopefully by now you already have a good idea of how to compile GCC. Let's refresh so we're all on the same page.

 

1. You've installed GCC from the Solaris 10 DVD and this step is complete.

 

2. You've added the bin directory for GCC to your PATH statement. /usr/sfw/bin/

 

3. You've add /usr/ccs/bin to your PATH statement after the directory for gcc.

 

4. You've verified that all the packages mentioned in Casper Dik's FAQ are installed on your system.

 

5. If you type 'gcc --version' from any directory it reports your currently installed version of GCC.

 

6. If you type 'make' from any directory it runs the program.

 

7. You've read through the GCC manual and setup all the optimization flags you think should be set for your system. If you're in doubt here ask for help or simply skip this step. Your programs will still compile.

 

8. You've ftp'd the current version of GCC from ftp://ftp.gnu.org/gnu/gcc

 

Ok, we're now ready to compile the compiler.

 

The first step as you already know is to unzip and then untar the gcc code onto the system.

 

After you've unzipped and untarred the tar ball, read through the "Install" directory. You can also peruse the gcc/doc directory if you desire. Be sure to check the 'host/target specific installation notes'.

 

After you're done reading the documents you're ready to run configure.

 

./configure -help |more, will list all the configure options that you can enable to build GCC. After you have selected your options, run configure again, and specify those options. An example of this is:

 

./configure --exec-prefix=/usr/sfw \
--bindir=/usr/sfw/bin \
--libdir=/usr/sfw/lib \
--infodir=/usr/sfw/info \
--mandir=/usr/sfw/man \
--with-local-prefix=/usr/sfw/include \
--enable-shared \
--enable-threads=solaris \
LDFLAGS="-L/usr/sfw/lib -R/usr/sfw/lib"

 

Press enter and let configure do its work. When it's finished it will create the config.status script so you don't have to type everything in all over again. Just copy the config.status file to someplace safe.

 

If you're happy with the switches you've selected above, you can save these off to a file so you can use the same switches again when you go to compile another program that uses configure. You can then set an environment variable called, CONFIG_SITE, to point to this file or directory that contains this file.

 

CONFIG_SITE can point to a directory or to a file. If you want it to point to a shell script then supply the full PATH and the name of the shell script. If you supply just a PATH statement then configure will append /share/config.site or /etc/config.site to the pathname to come up with the full PATH and filename. To avoid confusion you should consider supplying the full PATH and filename.

 

GNU suggests that at a minimum you set the CC environment variable inside of the script file.

 

You can set things such --exec-prefix as well as all the environment variables already mentioned in your config.site file.

 

If you specify a setting in a config.site file take care not to duplicate this setting on the command line.

 

The autoconf manual supplies the following sample script:

 

# config.site for configure
#
# Change some defaults.
test "$prefix" = NONE && prefix=/usr/share/sfw/gnu
test "$exec_prefix" = NONE && exec_prefix=/usr/sfw/gnu
test "$sharedstatedir" = '$prefix/com' && sharedstatedir=/var
test "$localstatedir" = '$prefix/var' && localstatedir=/var

 

# Give Autoconf 2.x generated configure scripts a shared default
# cache file for feature test results, architecture-specific.
if test "$cache_file" = /dev/null; then
cache_file="$prefix/var/config.cache"
# A cache file is only valid for one C compiler.
CC=gcc
fi

 

The first four lines check to see if --prefix, --exec_prefix, --sharedstatedir, and --localstatedir are already set. If they are not then it sets these variables to the PATHs listed above. Then it tests for a config.cache file and tells configure to create one if it currently does not exists. Finally it sets the CC variable to gcc.

 

There is something very interesting here. If you'll notice the line that has exec_prefix on it. The usual command line switch is --exec-prefix.

 

As with the other switches the leading -- has been removed but this variable has two parts to it that are connected by an undersore and not the usual dash.

 

You can use this to your advantage.

 

So if you want to use --enable-shared in your config.site file you just use the same convention.

 

--enable-shared

 

becomes

 

enabled_shared=yes

 

Drop the leading -- and convert the other dash to an underscore and you're all set.

 

Now we're ready to compile the compiler. It is normal to have compiler warnings scroll by when the compiler is running. Unless you're a developer you can generally ignore these warnings unless they cause compilation to fail.

 

Normally, you would now just type 'make' and let it run until it finishes. However, according to the install docs for gcc you need to add a couple of switches to the make command. So the make command should look like:

 

make CFLAGS='-O' LIBCFLAGS='-g -O2' \
LIBCXXFLAGS='-g -O2 -fno-implicit-templates' \
Bootstrap

 

A caveat. GCC is a 32-bit program. It will not compile with a 64-bit machine.

 

But I only have a 64-bit machine you say. What should I do?

 

Use:

 

export ABI=32

 

which will tell the compiler to only compile it as a 32-bit app. Don't worry because it will still compile 64-bit code.

 

So when you start configure and the first few lines scroll by you'll see:

 

i386-pc-solaris2.11

 

If that line has a 64 on it somewhere then eventually the compilation will fail with an error.

 

So:

 

x86_64-pc-solaris2.11

 

will eventually generate a wrong ELFCLASS error.

 

Ok, back to compilig GCC. After you've entered the command shown above then press enter and wait. At the end of the build process you should be sitting at a command prompt with no fatal errors on the screen. You're now ready to install your new compiler.

 

To do this first remove the old compiler. pkgrm package_name will take care of this.

 

Then we need to switch to root to do the install. su - takes care of that. Now we're finally ready to install the compiler. 'make install' will take care of that.

 

If you've chosen to install gcc into a different directory hierarchy adjust your PATH statement accordingly. You should now type gcc --version again to verify that gcc still works. Now you're ready to compile other software programs. Your next one should be the GNU version of make. Some people refer to this as gmake (GNU's make). To compile other programs just repeat what you did to compile gcc.

 

Next Section:  Build Problems (6 of 11)



Home Sitemap, About Page, Site Search Weblog
Compile C Code IPv6 Open Ports
Role Based Access Control Sendmail Configuration Stock Quotes

This Web Site Copyright © 1997 - 2012
by Alan Pae - All Rights Reserved