Linker Error

This is a discussion on Linker Error within the C Programming forums, part of the General Programming Boards category; Hi all, I have written a code for a program which detects whether a number is a factorial number or ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    69

    Linker Error

    Hi all,

    I have written a code for a program which detects whether a number is a factorial number or not. I am getting a linker error saying "undefined reference to WinMain@16" after compilation
    of my program. Kindly help me to solve this problem. Thank you. Below is my code:

    Code:
    #include<stdio.h>
    int main()
    {   
        int i,n,prod=1;
        printf("Enter n to be checked");
        scanf("%d",&n);
        if(n==1 || n==2)
        {
                printf("n is a factorial number");
        }
        else if(n>2)
        {   
        for(i=1;i<=n/2;)
        {
         while (prod<=n)
               {
               prod*=i;
               i++;
               }
        }
        }
        if(prod==n)
                    {
                    printf("factorial");
                    }
        else
                    printf("not factorial");
        system("pause");
        return(0);
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,560
    What compiler are you using, include the version information? What version of Windows are you using?

    Jim

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    69
    Quote Originally Posted by jimblumberg View Post
    What compiler are you using, include the version information? What version of Windows are you using?

    Jim
    Thank you for your prompt reply. I am using Mingw GCC compiler and windows seven enterprise edition.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    It thinks you are trying build a Windows executable instead of a console application. This is probably a setting somewhere but I've never used Mingw/GCC.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,371
    IIRC, try option "-mwindows"

    SDL :: View topic - SDL_mixer's playwave.exe linking error with SDL 1.2.15 on mi

    The above link implies missing or wrong order of "-lmingw32" can cause issue.

    Tim S.
    Last edited by stahta01; 01-26-2012 at 10:14 AM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker error help
    By bonks in forum C Programming
    Replies: 14
    Last Post: 03-17-2011, 08:18 AM
  2. Linker error
    By Spitball in forum C++ Programming
    Replies: 5
    Last Post: 08-17-2003, 07:28 AM
  3. linker error
    By :::::: in forum C++ Programming
    Replies: 1
    Last Post: 04-09-2003, 05:00 PM
  4. ...linker error...
    By tommy_cgl in forum C++ Programming
    Replies: 7
    Last Post: 04-01-2003, 04:52 AM
  5. ...linker error...2
    By tommy_cgl in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2003, 07:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21