Подключаю в проект библиотеки
#include "windows.h"
#include "winldap.h"
#include "winber.h"
#include "rpc.h"
#include "rpcdce.h"
#include "stdio.h"
выдает ошибки будто библиотеки и не подключились
D:\cpp_project\newDesktop\LDPA_Query.cpp:39: ошибка: undefined reference to `__imp_ldap_initW'
D:\cpp_project\newDesktop\LDPA_Query.cpp:42: ошибка: undefined reference to `__imp_ldap_set_optionW'
D:\cpp_project\newDesktop\LDPA_Query.cpp:43: ошибка: undefined reference to `__imp_ldap_connect'
D:\cpp_project\newDesktop\LDPA_Query.cpp:44: ошибка: undefined reference to `__imp_ldap_bind_sW'
D:\cpp_project\newDesktop\LDPA_Query.cpp:72: ошибка: undefined reference to `__imp_ldap_search_sW'
D:\cpp_project\newDesktop\LDPA_Query.cpp:84: ошибка: undefined reference to `__imp_ldap_unbind_s'
D:\cpp_project\newDesktop\LDPA_Query.cpp:86: ошибка: undefined reference to `__imp_ldap_msgfree'
D:\cpp_project\newDesktop\LDPA_Query.cpp:95: ошибка: undefined reference to `__imp_ldap_unbind'
При сборке qmake выдает следующее
:-1: предупреждение: Failure to find: windows.h
:-1: предупреждение: Failure to find: winldap.h
:-1: предупреждение: Failure to find: winber.h
:-1: предупреждение: Failure to find: rpc.h
:-1: предупреждение: Failure to find: rpcdce.h
:-1: предупреждение: Failure to find: stdio.h
Использую компилятор MinGW 7.3.0 64-bit for C++
Вопрос, где мне найти эти библиотеки что бы их добавить в проект?
Файл .pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
DEFINES += QT_DISABLE_DEPRECATED_BEFORE # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
LDPA_Query.cpp \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h \
windows.h \
winldap.h \
winber.h \
rpc.h \
rpcdce.h \
stdio.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
res.qrc
Файл .cpp (не мой, позаимствовал для теста)
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
#include <QString>
#include "windows.h"
#include "winldap.h"
#include "winber.h"
#include "rpc.h"
#include "rpcdce.h"
#include "stdio.h"
void MainWindow::LDAP_query()
{
//Name contains the username
PWCHAR hostName = NULL;
//PWCHAR Domain = NULL;
PWCHAR pMyDN = NULL;
//PWCHAR pUserName;
//PWCHAR pPassword;
LDAP* pLdapConnection = NULL;
ULONG version = LDAP_VERSION3;
//ULONG getOptSuccess = 0;
//ULONG connectSuccess = 0;
INT returnCode = 0;
// Convert String hostname to a wchar_t*
char const *hostName_2 = "host";
QString Test = QString::fromAscii(hostName_2);
hostName = (WCHAR*)(Test.utf16());
//Connverting Char to WCHAR to connect to Directory
char const *pMyDN_2 = "Ou=directory,Dc=Name,DC=office";
QString test2 = QString::fromAscii(pMyDN_2);
pMyDN = (WCHAR*)(test2.utf16());
//Open Connection
pLdapConnection = ldap_init(hostName, LDAP_PORT);
//Setting Connection Parm's
ldap_set_option(pLdapConnection, LDAP_OPT_PROTOCOL_VERSION, (void*)&version);
ldap_connect(pLdapConnection, NULL);
returnCode = ldap_bind_s(pLdapConnection, pMyDN, NULL, LDAP_AUTH_NEGOTIATE);
if(returnCode == LDAP_SUCCESS)
{
ui->statusbar->showMessage("Connection sucessfull");
}
else
{
ui->statusbar->showMessage("Connection unsucessfull");
}
//Variables for Search Results
LDAPMessage* pSearchResult;
PWCHAR pMyFilter = NULL;
char const *pMyFilter_2 = "(&(objectCategory=person)(objectClass=user))";
QString Test7 = QString::fromAscii(pMyFilter_2);
pMyFilter = (WCHAR*)(Test7.utf16());
PWCHAR pMyAttributes[6];
ULONG errorCode = LDAP_SUCCESS;
pMyAttributes[0] = (WCHAR*)QString("cn").utf16();
pMyAttributes[1] = (WCHAR*)QString("company").utf16();
pMyAttributes[2] = (WCHAR*)QString("department").utf16();
pMyAttributes[3] = (WCHAR*)QString("telephoneNumber").utf16();
pMyAttributes[4] = (WCHAR*)QString("memberOf").utf16();
pMyAttributes[5] = NULL;
errorCode = ldap_search_s(
pLdapConnection, // Session handle
pMyDN, // DN to start search
LDAP_SCOPE_SUBTREE, // Scope
pMyFilter, // Filter
pMyAttributes, // Retrieve list of attributes
0, // Get both attributes and values
&pSearchResult); // [out] Search results
if (errorCode != LDAP_SUCCESS)
{
ui->statusbar->showMessage("ldap_search_s failed with");
ldap_unbind_s(pLdapConnection);
if(pSearchResult != NULL)
ldap_msgfree(pSearchResult);
}
else
ui->statusbar->showMessage("ldap_search succeeded \n");
//here i like to receive the user's full name
//Closing Connection
ldap_unbind(pLdapConnection);
//ui->Test_Ausgabe -> setText(name);
}
#include "windows.h"не подключают в проект библиотеки. Вам стоит ознакомится с порядком сборки в С/С++, прежде всего с препроцессором и линкером. – user7860670 Mar 03 '20 at 09:40