[Date Prev][Date Next] [Chronological] [Thread] [Top]

Api OpenLdap C++

Hello all,

I am having problems to compile the code below with C++, in the
version oldest of the OpenLdap I did not have this problem.

extern "C" {
#include <stdio.h>
#include <ldap.h>

#define HOSTNAME "ldap://ldap.cb.sc.gov.br:389";
#define PORTNUMBER 389

int main(int argc, char *argv[])
      LDAP  *ld;
      char    *dn;
      int       version, rc;

      const char *root_dn = "uid=edm,ou=Users,dc=cb,dc=sc,dc=gov,dc=br";
      char *root_pass = "passtest";

      printf("Connecting %s in port %d...\n\n", HOSTNAME, PORTNUMBER);

      rc = ldap_initialize(&ld, HOSTNAME);
      if ( rc != LDAP_SUCCESS )
              printf("Error !");

      version = LDAP_VERSION3;
      ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version);

      rc = ldap_simple_bind_s(ld, root_dn, root_pass, LDAP_AUTH_SIMPLE );
      if (rc != LDAP_SUCCESS) {

              fprintf(stderr, "Error: %s\n", ldap_err2string(rc));

              return (1);



% c++ -I/usr/local/include -L/usr/local/lib -lldap test_ldap.cpp -o test_ldap
test_ldap.cpp: In function `int main(int, char**)':
test_ldap.cpp:31: error: `ldap_simple_bind_s' was not declared in this scope
test_ldap.cpp:40: error: `ldap_unbind' was not declared in this scope

devel:% uname -a
FreeBSD devel.cb.sc.gov.br 6.2-STABLE FreeBSD 6.2-STABLE #0: Mon May
28 08:58:45 BRT 2007
root@devel.cb.sc.gov.br:/usr/src/sys/i386/compile/DEVEL  i386

Used --> openldap-client-2.3.35 Open source LDAP client implementation

One another question, exists a API of the OpenLdap for C++?

Thanks, edm.

Ederson de Moura