Chris_45
Chris_45

Reputation: 9053

Unresolved external in C-program on Win 32 in Visual Studio 2008

Why doesn't this C-program compile and what does the err messages mean:

#include <stdio.h>
int main() {
    char op = ' ';
    char cont = ' ';
    int tal1 = 0;
    int tal2 = 0;
    int result;
    int ok = 1;
    printf("Welcome\n");
    do  {
        printf("Which one (+ - * /)? ");
        scanf("%c", &op);  fflush(stdin);
        printf("Number?: ");
        scanf("%d", &tal1); fflush(stdin);
        printf("Number: ");
        scanf("%d", &tal2);   fflush(stdin);
        ok=1;
        switch(op){
        case '+': 
            result=tal1+tal2;
            break;
        case '-':
            result=tal1-tal2;
            break;
        case '*':
            result=tal1*tal2;
            break;
        case '/':
            result=tal1/tal2;
            break;
        default:
            printf("Wrong\n");
            ok=0;
            break;
        }
        if(ok)
            printf("Answer: %d\n", result);
        printf("Continue? (j/n)"); fflush(stdin);
    }while (cont == 'j');
    printf("Thanks!\n");
    return 0;
}

Err mess: Error 4 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup MSVCRTD.lib Error 5 fatal error LNK1120: 1 unresolved externals

Upvotes: 0

Views: 548

Answers (2)

inkredibl
inkredibl

Reputation: 1993

You're compiling a Windows (win32) application but have main() function instead of WinMain().

You should either change the type of your project to some sort of console application (don't remember exactly how that's called) or read about writing Windows applications.

The problem is that win32 applications use WinMain() for their main function and implement a message loop in there. So when you try to compile win32 application without defining a WinMain() function the compiler complains about just that. Similar thing would happen if you would write a console application and would not provide a main() function.

Upvotes: 0

Frank Bollack
Frank Bollack

Reputation: 25186

Check your linker settings (Pproject Properties->Linker->System).

The SubSystem property should be set to CONSOLE

Upvotes: 1

Related Questions