错误'LINK:致命错误LNK1123:在转换为COFF期间失败:文件无效或损坏'在Visual Studio 2010 C ++上?

时间:2013-10-08 19:06:28

标签: c++ visual-studio-2010

使用Win32控制台应用程序编译代码时出现以下错误Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt'。 我尝试修复它进入Projects - >属性 - >一般 - >链接器 - >启用增量链接,我将其从“是”更改为否(/ 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;
} 

1 个答案:

答案 0 :(得分:1)

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

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

请查看此链接了解详情:

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

另见:

Building Console Applications