Visual Studio 2008 中 Win 32 上的 C 程序中未解决的外部问题

发布于 2024-08-05 10:57:50 字数 1179 浏览 5 评论 0原文

为什么这个 C 程序无法编译以及错误消息的含义是什么:

#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: 错误 4 错误 LNK2019:函数 ___tmainCRTStartup MSVCRTD.lib 中引用了无法解析的外部符号 _WinMain@16 错误 5 致命错误 LNK1120:1 个未解析的外部

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2024-08-12 10:57:50

检查链接器设置(Pproject Properties->Linker->System)。

子系统属性应设置为CONSOLE

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

The SubSystem property should be set to CONSOLE

故人的歌 2024-08-12 10:57:50

您正在编译 Windows (win32) 应用程序,但具有 main() 函数而不是 WinMain()。

您应该将项目类型更改为某种控制台应用程序(不记得确切的名称)或阅读有关编写 Windows 应用程序的信息。

问题在于 win32 应用程序使用 WinMain() 作为其主函数,并在其中实现消息循环。因此,当您尝试编译 win32 应用程序而不定义 WinMain() 函数时,编译器会抱怨这一点。如果您编写控制台应用程序并且不提供 main() 函数,也会发生类似的情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文