C++ LNK2019 unresolved external symbol stdlib

512 views Asked by At

I have a program that requires atol() in one of its functions. So I included stdlib.h but it doesn't seem to see it.

EDIT: I'm aware to use it, I should include stdlib.h. I did that but I'm still getting this error. The function:

void
intstr( char *t )
{
    long int atol( char * );
    long x;
    int i;
    x=atol(t);

    for(i=0;i<nilit;i++){
        if(x == ilit[i]){
        lsymb =symbol[nsymb++] = 250+i;
        return;}
    }
    if( 50 <= nilit){ 
        puts("** too many int literals**");
        exit(1);
    }
    ilit[nilit++] = x;
    lsymb = symbol[nsymb++] = 249 + nilit;
}

The error I get when I try to build

 error LNK2019: unresolved external symbol "long __cdecl atol(char *)" (?atol@@YAJPAD@Z) referenced in function "void __cdecl intstr(char *)" (?intstr@@YAXPAD@Z)
C:x\X\X\X\Debug\p8program.exe : fatal error LNK1120: 1 unresolved externals
1

There are 1 answers

1
Mr.C64 On BEST ANSWER

You have this code:

void
intstr( char *t )
{
    long int atol( char * );

What's the point of this atol() wrong declaration?
To use atol() in your code, just #include <stdlib.h>.

Note that the prototype of atol() is:

long atol( const char *str );

(The input parameter is a const pointer.)