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.
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})