-2

Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt'使用 Win32 控制台应用程序编译代码时出现以下错误。我尝试在进入项目->属性->常规->链接器->启用增量链接时对其进行修复,然后将其从“是”更改为否(/INCREMENTAL:NO),然后我尝试再次调试我的代码,但又得到了另一个错误信息 :

1>------ Build started: Project: Someproject, Configuration: Debug Win32 ------
1>project1.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\anne\documents\visual studio 2010\Projects\Someproject\Debug\Someproject.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我该如何解决?

#include <Windows.h>
#include <process.h>
#include <stdio.h>
#include <math.h>

volatile int counter = 0;

int isPrime(int n)
{
    for(int i = 2; i < (int)(sqrt((float)n) + 1.0) ; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

unsigned int __stdcall mythread(void*) 
{
    char* s;
    while (counter < 25) {
        int number = counter++;
        s = "No";
        if(isPrime(number)) s = "Yes";
        printf("Thread %d value = %d is prime = %s\n",
            GetCurrentThreadId(), number, s);
    }
    return 0;
}

int main(int argc, char* argv[])
{
    HANDLE myhandleA, myhandleB;
    myhandleA = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
    myhandleB = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);

    WaitForSingleObject(myhandleA, INFINITE);
    WaitForSingleObject(myhandleB, INFINITE);

    CloseHandle(myhandleA);
    CloseHandle(myhandleB);

    getchar();

    system("pause");
    return 0;
} 
4

1 回答 1

2

基本问题是您以某种方式在项目设置中指定了“Windows 应用程序”。您想要“控制台应用程序”。

Windows 应用程序使用“WinMain()”;控制台应用程序使用“main()”。

查看此链接了解详情:

错误 LNK2019:函数 ___tmainCRTStartup 中引用的未解析外部符号 _WinMain@16

也可以看看:

构建控制台应用程序

于 2013-10-08T19:15:28.053 回答