gcc is obviously installed somewhere in /opt/csw/, and gcc tends to add ${prefix}/lib to the libpath. One possible solution would be to modify AC_CHECK_LIB to use the -print-file-name option to locate the library if the compiler is gcc, and add the path to LDFLAGS if it isn't already there.