How to use the GNU linker with GCC?

OpenCSW GCC uses the Solaris linker by default. How can I tell it to use a different linker, for example the GNU linker?

asked: 2012-05-06 by: automaciej

automaciej answers:

There is a blog post explaining how to do it.

GCC's linker setting is set at build time and you cannot change it later. The OpenCSW GCC is built to use the Solaris linker. However, the Solaris linker can be told to not link, but call a different linker instead. To do this, you need to set the LD_ALTEXEC environment variable to e.g. /opt/csw/bin/gld. GCC will still be calling /usr/ccs/bin/ld, but /usr/ccs/bin/ld will delegate the work to /opt/csw/bin/gld.