Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to stricmp

I am trying to create a method that finds and replaces a string within a string but I seem to have some error at compile time with it. Could I get some help into figuring out what is going on?

void replaceString(char *find, char *replace)
{
    int len_string,i;
    char temp[30];
    len_string=strlen(find);
    while(1)
    {
        for(i=0;i<len_string;i++) temp[i]=fgetc(edit);
            temp[i+1]=NULL;
        /* the stricmp() is used for comparing both string. */
        if(stricmp(find,temp)==0)
        {
            fprintf(edit,"%s ",replace);
            fclose(edit);
            exit(1);
        }
        fseek(edit,-(len_string-1),1);
    }       
}

the error I get at compile time is undefined reference to stricmp. I know it isn't proper coding convention, but edit (object of type FILE) is currently a global variable.

like image 512
Jonathan Avatar asked May 07 '11 02:05

Jonathan


2 Answers

stricmp is Windows-specific. If you're not on Windows, strcasecmp.

like image 174
bmargulies Avatar answered Sep 17 '22 21:09

bmargulies


Actually, the error is at link time and NOT at compile time. Your code got compiled to an object file expecting to find implementation of stricmp while linking with other object files which it couldn't find. Hence the error: "undefined reference to stricmp". As bmargulies pointed out, the implementation is available in only on Windows libraries. You can switch to strcasecmp() if you are on POSIX compliant systems.

like image 20
Manish Avatar answered Sep 20 '22 21:09

Manish