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

    Question

  • I have already walk through every detail described in this forum but i find this problem keep jumping out in front of me

    I have installed psdk-x86.exe   
    added    corewin_express.vsprops   additional dependencies : 

                       kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib

    Executable files: C:\Program Files\Microsoft Platform SDK\Bin

    Include files: C:\Program Files\Microsoft Platform SDK\include
    Library files: C:\Program Files\Microsoft Platform SDK\lib

    has been included in tools option

    // WIN_APP.disabled = true;
    // WIN_APP_LABEL.disabled = true;
    // DLL_APP.disabled = true;
    // DLL_APP_LABEL.disabled = true;

    in step 4 has been done as well.


    my sorce code :

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>

    void Row_Echelon_new_asm(char *data[], int m, int n, int p);

    int main(){
        char con = 'Y';
        int P, size_row, size_col;
        char **input;
        int counter_0, counter_1;
        double duration;
        clock_t start,finish;

        srand( time(NULL) );

        while(con == 'Y' || con == 'y'){
            printf("Insert p (any prime number) and the matrix's row & column : ");
            scanf("%d %d %d", &P, &size_row, &size_col);
            printf("\n");
           
            input = malloc(size_row * sizeof(int *));
            for(counter_0 = 0 ; counter_0 < size_row ; counter_0++){
                input[counter_0] = malloc(size_col * sizeof(int));
            }
           
            for(counter_0 = 0 ; counter_0 < size_row ; counter_0++){
                for(counter_1 = 0 ; counter_1 < size_col ; counter_1++){
                    input[counter_0][counter_1] = (char)rand() % P;
                }
            }

            start = clock();
            Row_Echelon_new_asm(input , size_row , size_col , P);
            finish = clock();
            duration = (double)(finish - start) / CLOCKS_PER_SEC;

            printf("New method by asm : %f", duration);
            printf("\n");       

            printf("Again? (y / n) : ");
            scanf(" %c", &con);
            printf("\n");
        }
       
        return 0;
    }

    void Row_Echelon_new_asm(char *data[], int m, int n, int p){
        char a, b, c, i, j, k = 1, l, o, temp_1, temp_2 = 0, s1, s2, t1, t2;
        char *temp_n, *temp_p, *temp_t, s_temp, t_temp, flag, temp;
        char *array, *stack_0, *stack_1;
        char control;
        int counter, con = 0, con_2 = 8;

        //先做補數
       
        stack_0 = calloc(p , sizeof(int));
        stack_1 = calloc(p , sizeof(int));
        array = calloc(p , sizeof(int));
        array[1] = 1;

        for(i = 2 , j = 0 ; i < p ; i++){
            if(j >= 1){
                for(k = k ; k <= j ; k++){
                    if(i == stack_0[k]){
                        t2 = stack_1[k];
                        k++;
                        goto insert;
                    }
                }
            }
            a = p;
            b = i;
            for(s1 = 1 , t1 = 0 , s2 = 0 , t2 = 1, flag = 0 ; b > 1 ; flag++){
                c = a % b;
                s_temp = s1 - (a / b) * s2;
                t_temp = t1 - (a / b) * t2;
                a = b;
                b = c;
                s1 = s2;
                t1 = t2;
                s2 = s_temp;
                t2 = t_temp;
                if(flag % 2 == 0 && b == 1){
                    s2 = s1 -( a-1 ) * s2;
                    t2 = t1 - ( a-1 ) * t2;
                }
            }
    insert:
            if(t2 < 0)
                arrayIdea = (p * (p - 1) + t2) % p;
            else
                arrayIdea = t2;

            stack_0[j + 1] = t2;
            stack_1[j + 1] = i;
            j++;
        }   

    //    reduced row echelon

        for(i = 0 ; i < m && i < n ; i++){
            l = 0;
    start:
            for(j = i ; j < m ; j++){
                if(temp_2 >= n){
                    goto end;
                }
                temp_1 = data[j][temp_2];
                if(temp_1 * temp_1 > l * l){
                    l = temp_1;
                    o = j;
                }
            }
            if(l == 0){
                (temp_2)++;
                goto start;
            }                         

            temp_n = dataTime;
            dataTime = dataIdea;
            dataIdea = temp_n;                // successfully change leading number to greatest

            control = temp_2;
             temp_1 = array[(temp_n[temp_2] + p * (p - 1)) % p];
            temp_n[temp_2] = (temp_n[temp_2] * temp_1 + p * (p - 1)) % p;
            for(j = temp_2 + 1 ; j < n ; j++){
                temp_n[j] = (temp_n[j] * temp_1 + p * (p - 1)) % p;
            }
           
            o = i;
            for(j = 0 ; j < m ; j++){
                if(j == o){
                   continue;
                }
                if(control + 8 <= n){
                    temp_t = calloc(m , sizeof(int));
                    for(counter = temp_2 ; counter < control + 8 ; counter++){
                        temp_t[counter] = temp_n[counter] * data[j][temp_2];
                    }
                    temp_p = data[j];
                    __asm{
                        // do asm part by 8
                        pushad
                        mov     esi         , 0
                    L1:
                        movq    mm0         , temp_t[esi]
                        movq    mm1         , temp_p[esi]
                        psubb   mm1         , mm0
                        movq    temp_p[esi] , mm1
                        add     esi         , 8
                        movzx   eax         , control                 
                        add     eax         , 8                       
                        mov     control     , al                     
                        cmp     eax         , 8                       
                        JG      end1
                        Loop    L1
                        JMP     end2
                    end1:
                        sub     eax         , 8
                        mov     control     , al                     
                        mov     eax         , 8                       
                        mov     con         , eax                     
                    end2:
                        emms
                        popad
                    }
                    if(con == 1){
                        // do rest
                        for(counter = control ; counter < n ; counter++){
                            temp = (p * (p - 1) + temp_p[counter] - temp_t[counter]) % p; 
                            temp_p[counter] = temp;
                        }
                        con = 0;
                        continue;
                    }
                }
                temp_p = data[j];
                temp_1 = data[j][temp_2];
                for(k = temp_2 ; k < n ; k++){
                    temp = (p * (p - 1) + temp_p[k] - temp_n[k] * temp_1) % p; 
                    temp_p[k] = temp;
                }
            }
    end:
            temp_2++;
        }
    }


    Please tell me what is going on @@"  

      Desperate


    Monday, January 16, 2006 7:05 AM

Answers

  • When you created the project, you made the wrong choice of application type. When asked whether your project was a console application or a windows application or a DLL or a static library, you made the wrong chose windows application (wrong choice).

    Go back, start over again, go to File -> New -> Project -> Win32 Console Application -> name your app -> click next -> click application settings.

    For the application type, make sure Console Application is selected (this step is the vital step).

    The main for a windows application is called WinMain, for a DLL is called DllMain, for a .NET application is called Main(cli::array<String ^> ^), and a static library doesn't have a main. Only in a console app is main called main

    Monday, January 16, 2006 11:47 AM
  • LeXXik:

    Unfortunatly thats not a very good option on the windows applications. It may change the entry point to main, but doing that you lose all of the CRT initialization because the actual entry point isn't WinMain, but MainCRTStartup.

    It is easier to change the project types by recreating the project rather than changing the compiler settings since there are a few to change and you could forget some.

    Monday, March 20, 2006 11:13 PM

All replies

  • When you created the project, you made the wrong choice of application type. When asked whether your project was a console application or a windows application or a DLL or a static library, you made the wrong chose windows application (wrong choice).

    Go back, start over again, go to File -> New -> Project -> Win32 Console Application -> name your app -> click next -> click application settings.

    For the application type, make sure Console Application is selected (this step is the vital step).

    The main for a windows application is called WinMain, for a DLL is called DllMain, for a .NET application is called Main(cli::array<String ^> ^), and a static library doesn't have a main. Only in a console app is main called main

    Monday, January 16, 2006 11:47 AM
  • GoTo Project Properties -> Configuration Properties -> Linker -> Advanced

    Put "main" to the "Entry Point" field.

    Monday, March 20, 2006 1:12 PM
  • LeXXik:

    Unfortunatly thats not a very good option on the windows applications. It may change the entry point to main, but doing that you lose all of the CRT initialization because the actual entry point isn't WinMain, but MainCRTStartup.

    It is easier to change the project types by recreating the project rather than changing the compiler settings since there are a few to change and you could forget some.

    Monday, March 20, 2006 11:13 PM
  • Thank you, crescens2k. I didn't know that.
    Wednesday, March 22, 2006 12:15 PM
  • hi,
    i am facing the same errors but i want to link statically . so i don't want to ignore libc libraries and i have tried with all the subsystems(console and windows) but nothing works . There is no minimum use of ATL also. There is a _DllMainCRTStartup function which is set as the entry and one more thing to note is the file is a .c file . i am quoting this because when i rename the file to .cpp and remove the entry point .its builds without linker errors. But unfortunately i am not allowed to do this.The configuration is Win32/Release.

    Hope these information is enough. Can any one help at the earliest

    LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

    Tuesday, March 11, 2008 1:23 PM
  • About solutions that are *easier*:

    Go to "Linker settings -> System". Change the field "Subsystem" from "Windows" to "Console". Done.

    Advice of going back to recreate the whole project seems very frustrating and cumbersome to trust... I think intuitively there is no need for such rigid requirements.
    • Proposed as answer by LuisGP Monday, February 09, 2009 10:14 AM
    Sunday, April 20, 2008 8:10 AM
  • Since this is the top search result for this error, here's how I encountered and fixed it:

     

    (Visual Studio 2008)

     

    1) Created new Visual C++ "Win32 Project"

    2) Deleted everything except the primary .cpp file

    3) Deleted everything in the primary .cpp file except for _tWinMain function

    4) Added #include <windows.h>

     

    Building at this point returned the error above. I had to add the following back in to fix it:

     

    #include <tchar.h>

     

    which defined the following:

     

    #define _tWinMain   wWinMain

     

    then everything built fine.

    Tuesday, July 08, 2008 3:49 PM
  • Thank you for this you are a life saver and wonderful!!

     

    Friday, September 12, 2008 2:59 AM
  • That's worked fine for me.

    Thanks!
    Monday, February 09, 2009 10:14 AM
  • Hi Guys

    I dont know how did it work for you but when i tried this solution it leaded me no where.

    I am still having the same issue. Please let me know because i must be doing something wrong. which i am not able to see.

    Thanks

    Arun Mittal
    Tuesday, June 23, 2009 2:51 AM
  • Do you have a WinMain or _tWinMain method in the code?
    Do you have a main or _tmain method in the code?

    The error unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup indicates that you are building with /SUBSYSTEM:WINDOWS in the linker options and "Use Unicode Character Set" but that the _tWinMain entry point is not present.

    Your entry point method should look like:

    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    { //... }
    If you have a main() function as the intended entry point - i.e. are building a CONSOLE app, then you need to make sure that the subsystem the linker uses is CONSOLE in Project properties\Configuration Properties\Linker\System\SubSystem

    and the entry point needs to look like:

    int _tmain(int argc, _TCHAR* argv[])
    { //... }
    
    Wednesday, June 24, 2009 1:27 AM
  • I also meet the same problem today, but its not the reason you have provided above.

    It's because in my project configuration, "configuration properties -> C/C++ -> Output Files -> ASM List Location/Object File Name/Program Database File Name"

    If the value is ".\obj\Release", the link error occurs. I observed that the compiler generates some release.* files in the directory ".\obj\"

    So i change the value to ".\obj\Release\". This time the compiler generates output files to ".\obj\Release\" diretory. 

    Wish this would help.
    Sunday, September 06, 2009 1:08 AM
  • Thanks J. Spraul; that's what I was missing. I find coding for TCHARs cumbersome, and only want to build with Unicode character set, so instead of doing what you suggested, I changed _tWinMain to wWinMain. If you're building with Multi-Byte character set, change _tWinMain to WinMain.
    Wednesday, March 23, 2011 1:48 PM
    • If you don't got it with above methods, try this.

      Try to change Properties -> Linker -> System -> SubSystem

      from Windows (/SUBSYSTEM:WINDOWS) to Console (/SUBSYSTEM:CONSOLE)

      My situation like this: change the project default property "Use of MFC" form "Use Standard Windows Libraries" to "Use MFC in a Static Library", and then it  can not be compiled & output " error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup", i tried it and it worked.  By the way, before change the property, project can becompiled successfully.

    Wednesday, September 05, 2012 8:39 AM