开发者

error LNK2019 unexplainable when trying to port openldap to windows

I'm working on Windows XP with Visual Studio 2005.My project is a Cmake project created after creating an LDAP abstraction API on Linux. I'm trying somehow to make it work on Windows.

I've got an unusual linking error of type LNK2019

main.obj : error LNK2019: symbole externe non résolu _strcpy référencé dans la fonction _menu

it happens that this function is in my main.c and the linking error above is coming from my other file LDAP.C which contain the load_values_from_attr() function

/****/

static INT16 load_values_from_attr(t_LdapSearchContext ctx,
    UINT32 result_max_count, LDAP *ld, LDAPMessage *result_message,
    BerElement *ptr)
{
    UINT16 j=0;
    UINT16 i=0;

    char *str_attr; 
    struct berval **str_values;
    str_attr=ldap_first_attribute(ld, result_message, &ptr);

    if (str_attr == NULL) return 1;
    str_values=ldap_get_values_len(ld, result_message, str_attr);
    strcpy(ctx.attributs[i].attrs, str_attr);
    while(str_values[j]!=NULL && j+1<RESULT_WIDTH)
    {
        strncpy(ctx.attributs[i].values[j+1].val,
            str_values[j]->bv_val,MAX_LENGTH);
#ifdef WIN32
        ber_bvfree(str_values[j]); // <<< here is my problem
#endif
        j++;
    }

/****/

When I delete or comment t开发者_Go百科he line with: ber_bvfree(str_values[j]); the Linking error happen, and when I leave it there, the program compiles and can be executed but segfault on it (which is another story).

I can't figure out why the linker is behaving this way.


Finally !! after working on linker option in visual studio , i figure our that there was /NODEFAULTLIB:msvcrtd.lib enable , option that screwed the linker. without it linker can link correctly the different objects. (this option ve been enable after observing there was lnk2001 linker problem in my code as well)

NB: I still can t tell why this option is involved in trouble linking my own object , usualy /NODEFAULTLIB:msvcrtd.lib is used to disable the default library msvcrtd.lib inclusion.

i hope this will help somebody

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜