pkgtool error: \"libtool: ar: not found\"

One of the things about pkgsrc is that it's very sensitive to paths and which compiler you use. (And fair enough; the whole process of bootstrapping a working set of tools for eight hundred thousand different OS' is ridiculous enough that it's a wonder it works at all. But I digress.)

Case in point: Solaris 10 machine today, installing pkgsrc on it for the first time. I successfully compiled gcc34, added GCC_REQD=3.4 to mk.conf, and then went to compile kile. During compiling of Mesalibs, one of its 3.2x10^6 dependencies, I got this error during the final linking phase:

/opt/pkg/bin/libtool: ar: not found

Naturally it was there in my path, so WTF?

I eventually came across a message to the pkgsrc user's list which suggested rebuilding libtool-base. This made a certain amount of sense to me, as I'd built that package using the bootstrap (ie, not-installed-from-pkgsrc) version of gcc to compile it; it was before I figured out the GCC_REQD directive. So I ran:

$ pkg_delete libtool
$ cd /opt/pkgsrc/devel/libtool
$ bmake clean && bmake install
$ cd /opt/pkgsrc/graphics/MesaLib
$ bmake clean && bmake install

and everything was right again.