gpt4 book ai didi

C++ 使用 ldap.h 中的 ldap_bind

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:47 24 4
gpt4 key购买 nike

我正在尝试使用 ldap_bind,但出现此错误。

error: âldap_bindâ was not declared in this scope

代码:

#include <lber.h>
#include <ldap.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
LDAP *ld;

char *ldap_host = "ldap://localhost";
int ldap_port = 389;
int auth_method = LDAP_AUTH_SIMPLE;
int desired_version = LDAP_VERSION3;
char *root_dn = "ou=people,dc=localhost,dc=local";
char *root_ps = "password";

int result;

result = ldap_initialize(&ld, ldap_host);

cout << "result: " << result << endl;

result = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version);

cout << "result: " << result << endl;

result = ldap_bind_s(ld, root_dn, root_ps, auth_method);

cout << "result: " << result << endl;
}

我正在用这个命令编译

g++ ldap.cpp -llber -lldap -o prog

TIA

最佳答案

我没有使用 OpenLDAP 的经验,但从标题看来您需要:

extern "C" {
# define LDAP_DEPRECATED
# include <ldap.h>
# include <lber.h>
}

关于C++ 使用 ldap.h 中的 ldap_bind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5282937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com