With the command line /usr/sfw/bin/gcc -I/usr/local/opt//openldap/openldap-2.3.27/include -L/usr/local/opt/openldap/openldap-2.3.27/lib/libldap.a -L/usr/local/opt/openldap-2.3.27/lib/liblber.a ldaptest.c
Your paths on your -L lines don't match.
For that matter, I think you're confusing big L with little l. Typically you'd, assuming those paths are right,
gcc -I/usr/local/opt/openldap/openldap-2.3.27/include -L/usr/local/opt/openldap/openldap-2.3.27/lib -lldap -llber ldaptest.c
big L is search path, little l is library name (-lfoo => libfoo.{a,so})
Looks like you're trying to use .a static libraries. If you use .so shared libraries, you'll probably want an RPATH. You can Google for that or ask the Solaris community for help.