0

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 the 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.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
LELEVATOR
  • 1
  • 2
  • My french is rusty, and was never that good to start with, but isn't the linker complaining about a reference to `strcpy` in the function `menu`? Why do you beleive that the linker error is in the function you've shwon? I do note the call to `strcpy`. Oh, and what happens if you replace strcpy with `strncpy`, which you are already using. – torak Aug 03 '10 at 17:23
  • i think the linker is complaining about a reference to _strcpy wich i think is the version of strcpy convert into the main.o object created in the previous step by the precompilator, and yeah you r right it seems like it can t find the proper definition of it (i got the right header). i can t try right now to change strcpy in strncpy but i ll whenever i can. however if i leave ber_bvfree(str_values[j]); i don t get linker errors , and whenever i try to comment this line or remove it , linker errors are their. It might come from something else but i really have no idea – LELEVATOR Aug 03 '10 at 22:36
  • well i m still invastigating why the linker act this way , and replace all my strcpy with memcpy combine with strlen , and still it gives me 1>main.obj : error LNK2019: symbole externe non résolu _strlen référencé dans la fonction _menu ...(unresolved reference to _strlen ).Notice that this linking error is just the first among 73 linking errors following – LELEVATOR Aug 04 '10 at 09:13
  • UPDATE: ber_bvfree(str_values[j]); is defined in lber.h BUT , as you might know by now : if it s is deleted from the file i got a linker error, i noticed aferwards that i must use at least a function from lber.h so the linker allow me to compile(even though the function is irrevlevant ). i m getting closer from truth but still don t have clue why the linker behave this odd – LELEVATOR Aug 04 '10 at 13:38

1 Answers1

0

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

LELEVATOR
  • 1
  • 2