Compiling gcc on Solaris 10 x86

Here are step by step instructions for compiling gcc 4.2.4 on a fresh installation of Solaris 10 x86. Some key information came from a post by Andreas Höschler on the discuss-gnustep mailing list.

First you will need to get pkgutil (more info here). Download it:


Tip: if you are running Solaris in VirtualBox then you can easily move it over using sshfs (see my previous post for details on using sshfs with a VirtualBox instance).

To install it and update the catalogue (I assume that everything is done as root from now on):

export PATH=$PATH:/opt/csw/bin
pkgadd -d pkgutil-sparc.pkg
pkgutil -U

It’s handy to have bash, wget, vim, and screen:

pkgutil -i bash wget vim screen

A few things that we’ll need for building gcc:

pkgutil -i binutil autoconf automake gtar bzip2 gmake

I don’t think that all of these exports are necessary apart from the path but my build worked with all of them:

export LIBRARY_PATH="/usr/local/lib"
export LIBRARY_PATH="/usr/local/lib"
export LD_OPTIONS="-L/usr/local/lib -R/usr/local/lib"
export PATH=$PATH:/usr/bin:/usr/sfw/bin:/opt/csw/bin:/usr/ccs/bin

I used the GNU assembler and the Sun linker:

# /usr/sfw/bin/gas -v
GNU assembler version 2.15 (i386-pc-solaris2.10) using BFD version 2.15
# /usr/ccs/bin/ld -V
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.493

Make sure that your ld and gas give same or later versions.

To compile gcc you will need gmp and mpfr:

gtar jxf gmp-4.2.4.tar.bz2
cd gmp-4.2.4
./configure --prefix=/usr/local
gmake install
gmake check
cd ..
gtar jxf mpfr-2.4.1.tar.bz2
cd mpfr-2.4.1
./configure --prefix=/usr/local
gmake install
cd ..

I did a full install of Solaris 10 so I ended up with this older gcc compiler:

-bash-3.00$ /usr/sfw/bin/gcc -v
Reading specs from /usr/sfw/lib/gcc/i386-pc-solaris2.10/3.4.3/specs
Configured with: /builds/sfw10-gate/usr/src/cmd/gcc/gcc-3.4.3/configure --prefix=/usr/sfw --with-as=/usr/sfw/bin/gas --with-gnu-as --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++ --enable-shared
Thread model: posix
gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)

We will use that version of gcc to compile the newer one.

Warning: gcc is supposed to be compiled in a subdirectory of the main source tree. You can end up in trouble if you just run ./configure in the top level directory. Instead we work in the objdir directory. Pick a close mirror from this list and then compile gcc (note that you need all of the environment variables (the export lines) from before). If it makes any difference, I did this in a bash shell, not sh (the default for root on Solaris).

wget http://your-closest-mirror/.../gcc-4.2.4.tar.bz2
gtar jxf gcc-4.2.4.tar.bz2
cd gcc-4.2.4
mkdir obj
cd objdir
../configure --with-gnu-as --with-as=/usr/sfw/bin/gas 
--without-gnu-ld --with-ld=/usr/ccs/bin/ld --enable-shared 
--disable-nls --enable-languages=c,c++,objc,fortran 
gmake install

Now make sure that /usr/local/bin is early enough in your path. For example:

export PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/opt/csw/bin:/usr/ccs/bin

And we have success:

# which gcc

# gcc -v
Using built-in specs.
Target: i386-pc-solaris2.10
Configured with: ../configure --with-gnu-as --with-as=/usr/sfw/bin/gas --without-gnu-ld --with-ld=/usr/ccs/bin/ld --enable-shared --disable-nls --enable-languages=c,c++,objc,fortran --disable-multilib
Thread model: posix
gcc version 4.2.4

I had no luck with the gcc 4.4.x packages available via pkgutil on x86 basically due to a a known problem.

I also tried to build gcc 4.4.1 from source and it failed like this:

checking whether /export/home/carlo/gcc-4.4.1/build1/./gcc/xgcc
-B/usr/local//i386-pc-solaris2.10/lib/ -isystem
/usr/local//i386-pc-solaris2.10/include -isystem
/usr/local//i386-pc-solaris2.10/sys-include  -m64 supports -pedantic ...
checking whether /export/home/carlo/gcc-4.4.1/build1/./gcc/xgcc
-B/usr/local//i386-pc-solaris2.10/lib/ -isystem
/usr/local//i386-pc-solaris2.10/include -isystem
/usr/local//i386-pc-solaris2.10/sys-include  -m64 and cc understand -c
and -o together... yes
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking whether byte ordering is bigendian... unknown
configure: error: unknown endianness
presetting ac_cv_c_bigendian=no (or yes) will help
gmake[1]: *** [configure-target-libiberty] Error 1
gmake[1]: Leaving directory `/export/home/carlo/gcc-4.4.1/build1'
gmake: *** [all] Error 2

Other people hit this same problem but I couldn’t find a solution.

Archived Comments

Date: 2013-11-05 13:56:41.210158 UTC

Author: Stephen L

Doesnt work for me. The compile of gmp fails straight away with

libtool: link: only absolute run-paths are allowed

Date: 2014-07-14 11:44:54.794208 UTC

Author: Aejaz

don’t use this option export LDFLAGS=”-RLIBDIR”, gmp will install, if you have already set it use export LDFLAGS=

Date: 2014-07-24 14:58:44.657682 UTC

Author: UX-admin

Doesnt work for me. The compile of gmp fails straight away with libtool: link: only absolute run-paths are allowed.

That’s because of the dumbass libtool (or rather, the author of
it): libtool has no notion of the special $ORIGIN ld keyword. There
are multiple possible fixes for that:

– never use LDFLAGS; O=’$$O’; export O; ORIGIN=’$ORIGIN’; export ORIGIN; LD_OPTIONS=’$ORIGIN:$ORIGIN/../../lib:$ORIGIN/../lib:/opt/gcc/lib’; export LD_OPTIONS

– patch the idiotic libtool by applying the following patch, offsets will vary depending on the version of libtool, but the fix is always the same:

--- libtool.orig
+++ libtool
@@ -5038,13 +5038,6 @@
        rpath | xrpath)
-         # We need an absolute path.
-         case $arg in
-         [\/]* | [A-Za-z]:[\/]*) ;;
-         *)
-           func_fatal_error "only absolute run-paths are allowed"
-           ;;
-         esac
          if test "$prev" = rpath; then
            case "$rpath " in
            *" $arg "*) ;;
@@ -5351,13 +5344,6 @@
        func_stripname '-R' '' "$arg"
-       # We need an absolute path.
-       case $dir in
-       [\/]* | [A-Za-z]:[\/]*) ;;
-       *)
-         func_fatal_error "only absolute run-paths are allowed"
-         ;;
-       esac
        case "$xrpath " in
        *" $dir "*) ;;
        *) xrpath="$xrpath $dir" ;;

apply the patch with:

/usr/sfw/bin/gpatch -uNp0; libtool.patch

LD_OPTIONS is a very powerful variable, because the link editor will inject into his option stream whatever is in it right before the final link-edit stage. It’s basically a backdoor override into the linker, and as such, will work with any compiler in existence on Solaris which uses ld. LD_OPTIONS enables compiling most software with Sun Studio compilers, which produce much better / faster / more optimized code than GCC, but this trick works with GCC just as well.

With this patch and LD_OPTIONS, or a combination of both, it is possible to build 99% of the freeware open source software on Solaris in record times without any hassles. Whatever won’t build with Sun Studio will build with GCC with a combination of these two applied, unless it’s kernel code for a non SunOS kernel.

To wit:

Using built-in specs.

Target: sparc-sun-solaris2.10
Configured with: ../gcc-4.9.1/./configure --prefix=/opt/gcc --libexecdir=/opt/gcc/lib --libdir=/opt/gcc/lib --with-mpc=/opt/gcc --with-mpfr=/opt/gcc --with-gmp=/opt/gcc --with-local-prefix=/opt/gcc --with-as=/usr/ccs/bin/as --without-gnu-as --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++,fortran --enable-shared --disable-bootstrap --with-libiconv-prefix=/opt/gcc --with-system-zlib --disable-nls --enable-threads=posix : (reconfigured) ../gcc-4.9.1/./configure --prefix=/opt/gcc --libexecdir=/opt/gcc/lib --libdir=/opt/gcc/lib --with-mpc=/opt/gcc --with-mpfr=/opt/gcc --with-gmp=/opt/gcc --with-local-prefix=/opt/gcc --with-as=/usr/ccs/bin/as --without-gnu-as --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++,fortran --enable-shared --disable-bootstrap --with-libiconv-prefix=/opt/gcc --with-system-zlib --disable-nls --enable-threads=posix
Thread model: posix
gcc version 4.9.1 (GCC)

Post scriptum:

on Solaris, always build GCC to use /usr/ccs/bin/as and
/usr/ccs/bin/ld, irrespective of platform, for performance and
because GNU tools have too many bugs, as well as are missing platform
support. One cannot fully utilize the full platform support on Solaris
with GNU assembler and linker. That is even stated in the official
GNU compiler collection documentation.

Date: 2014-07-24 15:04:33.148973 UTC

Author: UX-admin

Whoops, LD_OPTIONS should be:

LD_OPTIONS='-B direct -z ignore -R$ORIGIN:$ORIGIN/../../lib:$ORIGIN/../lib:/opt/gcc/lib'; export LD_OPTIONS

Compiling gambit from sourceforge on Ubuntu 9.04

Here are notes on compiling gambit revision 6294 (the current latest) from the SourceForge gambit repository.

There is a problem with libtool on Ubuntu 8 and 9, that will cause the build process to fail with an error like this:

../../ libtool: ....    X--tag=CXX: command not found

The only workaround is to use an older version of libtool from Ubuntu hardy. Here is how to install it:

$ sudo aptitude purge libtool
$ wget
$ sudo dpkg -i libtool_1.5.26-1ubuntu1_i386.deb

It is helpful to “pin” this package so that it won’t be automatically updated when running apt-get dist-upgrade. Edit /etc/apt/preferences (if the file doesn’t exist then just create it) and write this:

Package: libtool
Pin: version 1.5.26-1ubuntu1
Pin-Priority: 1001

This will keep libtool at version 1.5.26-1ubuntu1.

Now to install the latest version of gambit:

$ sudo aptitude install autoconf autotools-dev svn automake
$ svn co gambit
$ cd gambit/trunk/gambit/
$ aclocal
$ autoconf
$ autoheader
$ automake

The autoheader command is probably not necessary but I’m mentioning it because it’s part of the usual process to make a GNU configure script.

Now make and install as usual:

$ ./configure --prefix=$HOME/gambit
$ make
$ make install

To run gambit add these lines to $HOME/.bashrc:

export LD_LIBRARY_PATH=$HOME/gambit/lib/
export PATH=$PATH:$HOME/gambit/bin/

Open a terminal and run gambit.

Crackle in audio (Ubuntu 8.04/9.04) fix

The left audio channel on my work computer crackled badly. Ubuntu 8.04. Soundcard info from lspci:

00:1b.0 Audio device: Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller (rev 01)

Remove snd_hda_intel:

$ sudo modprobe -r snd_hda_intel
FATAL: Module snd_hda_intel is in use.

$ sudo lsof /dev/snd/* | grep mixer
mixer_app 9593 carlo   20u   CHR  116,0      11357 /dev/snd/controlC0

$ kill -9 (pid of mixer_app)

The fix: load with position_fix and model parameters.

$ sudo modprobe snd-hda-intel position_fix=1 model=3stack

Then use alsamixer to turn up and unmute main/pcm/etc.

Solaris 10 in VirtualBox quickstart

How to install Solaris 10 in VirtualBox with an Ubuntu 9.04 host.

First, download the installer DVD. Make a VirtualBox instance of type Solaris, mount the ISO file, and do the install. It’s all fairly straightforward (say yes to all the defaults).

You will probably want to be able to ssh to your Solaris installation. To do this, assuming that your VirtualBox instance is called Solaris10, run these commands in a terminal (taken from here):

VBoxManage setextradata Solaris10  "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/Protocol" TCP
VBoxManage setextradata Solaris10  "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata Solaris10  "VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/HostPort" 2222

Check that the redirect has been added (the last 3 lines):

$ VBoxManage getextradata Solaris10 enumerate
VirtualBox Command Line Management Interface Version 3.0.6
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/ShowMiniToolBar, Value: yes
Key: GUI/MiniToolBarAlignment, Value: bottom
Key: GUI/LastCloseAction, Value: save
Key: GUI/LastWindowPostion, Value: 4,-33,1016,522,max
Key: GUI/Fullscreen, Value: off
Key: GUI/Seamless, Value: off
Key: GUI/AutoresizeGuest, Value: on
Key: GUI/MiniToolBarAutoHide, Value: on
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/Protocol, Value: TCP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/GuestPort, Value: 22
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/ssh/HostPort, Value: 2222

This will redirect port 2222 on localhost to port 22 in the guest. In other words,

ssh -p 2222 user@localhost

will log you in. Note that an initial install of Solaris 10 will have only the root account, and by default root is not allowed to log in via ssh. So open a terminal in Solaris and add a user (-g staff makes this an administrator):

# useradd  -d /export/home/username -g staff -m -s /bin/bash username
# passwd username
(set the password here)

One final note: if you need to edit ssh options in /etc/ssh/, there is no /etc/init.d/sshd command to restart sshd. Instead use

svcadm restart ssh

It works:

$ ssh -p 2222 localhost
Last login: Mon Sep 14 14:34:09 2009 from
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
-bash-3.00$ uname -a
SunOS unknown 5.10 Generic_139556-08 i86pc i386 i86pc

A quick and easy way to get to the Solaris filesystem from the host is to use sshfs:

sudo aptitude install sshfs
sudo adduser username fuse

Log out and log in to activate the group change.

Now mount the Solaris instance in your home directory:

mkdir $HOME/solaris
sshfs username@localhost:/ $HOME/solaris/ -p 2222

I find that sshfs is very handy for working with remote systems.

Compiling gambit-0.2007.12.04 on Ubuntu 9.04

The stable release 2007.12.04 of the game theory package Gambit does not compile out of the box on Ubuntu 9.04. The problem is just a few missing #include lines, probably because the gcc header files have been updated since 2007.

Here is a patch: gambit-0.2007.12.04-ubuntu-9.04-patch. To use the patch do the following.

Unpack a fresh copy of Gambit:

tar zxf gambit-0.2007.12.04.tar.gz

Save the patch in the same directory; apply the patch:

cd gambit-0.2007.12.04
patch -p1 < ../gambit-0.2007.12.04-ubuntu-9.04-patch

Now configure and make as usual:

make install

Archived Comments

Date: 2009-09-15 16:44:23 UTC

Author: Ryan

Very helpful — thanks!