Wednesday, 15 July 2015

c++ - Generate lib from dll -> error on exec -



c++ - Generate lib from dll -> error on exec -

i'm trying utilize sun ldap c sdk (https://oss.oracle.com/projects/sun-ldapcsdk/). zip include .h , .dll, not .lib need generate .lib. utilize dumpbin.exe, expdef.exe (http://purefractalsolutions.com/show.php?a=utils/expdef) , lib.exe nsldap32v50.dll. extract of def file :

library nsldap32v50.dll exports ldap_abandon @10 ldap_add @11 ldap_unbind @13 ldap_compare @19 ldap_delete @20 ldap_result2error @21 ldap_err2string @22 ldap_modify @23 ldap_modrdn @24 ldap_open @25 ldap_first_entry @26 ldap_next_entry @27 ldap_get_dn @30 ldap_dn2ufn @31 ldap_first_attribute @32 ldap_next_attribute @33 ldap_get_values @34 ldap_get_values_len @35

little code test :

#include <ldap.h> int main(int argc, _tchar* argv[]) { ldap *ld; ldapmessage *result, *e; berelement *ber; char *a, *dn; char **vals; int i; int ldversion = ldap_version3; int debuglevel = 7; ldapcontrol **ctrls = null; ldap_set_option(null, ldap_opt_debug_level, &debuglevel); /* handle ldap connection */ std::cout << "hellow world !" << std::endl; homecoming 0; }

on linking have 1 error :

testldapsun.obj : error lnk2001: unresolved external symbol _ldap_set_option@12 testldapsun.exe : fatal error lnk1120: 1 unresolved externals

the problem is, linker search _ldap_set_option@12 lib have _ldap_set_option. prepare error modify .h files :

before :

#define ldap_pascal __stdcall #define ldap_call ldap_pascal ldap_api(int) ldap_call ldap_set_option( ldap *ld, int option, const void *optdata );

after :

#define ldap_pascal __cdecl #define ldap_call ldap_pascal ldap_api(int) ldap_call ldap_set_option( ldap *ld, int option, const void *optdata );

ok, linker works without warning. starting .exe file, ok end error

run-time check failure #0 - value of esp not saved across function call. result of calling function pointer declared different calling convention.

i think error come modification of __stdcall __cdecl o .h files without linker can't link.

any thought ?

thanks ;)

the export definition file not have entry ldap_set_option. therfore import library not have symbol resolve linker reques. reason missing symbol in .def file dll doesn't import it.

check .map file module resolves external symbol _ldap_set_option. lookup right implementation , utilize it.

c++ dll linker

No comments:

Post a Comment