# Linker Error! Oh No!

Printable View

• 10-22-2007
gnimblegnome
Linker Error! Oh No!
OK heres the deal see, I'm playing around with C++'s rand functions n' such, When I decide I want to make a dice rolling sim. here is what I have:

Code:

```/******************************************  *          Die Roll Simulator          **  *    Coded by Seth Collins            **  *  Made to provide random numbers as  **  *    Quickly and efficeintly as dice    **  ******************************************/   /* Includes: iostream, ctime, windows.h, cstdlib, time.h */ #include <iostream>  #include <ctime>   #include <windows.h>   #include <cstdlib>     #include <time.h> /* Namespace: STD standard */ using namespace std; /* Variables:  * iSides = integer, reprisents number of sides on die  * iNumbr = integer, represents number of dice  * iTotal = integer, total after rolled dice are added togather  */ int iSides; int iNumbr; int iTotal; /*RandInt Function  *creates RandInt funct for easy reading  */ int RandInt(int a, int b){     return a + rand() % (b - a + 1); } /* d4 Function  * This defines the four sided die  */ int d4(int iNumbr){     for ( true;iNumbr;iNumbr--){                     srand(unsigned(time(NULL)));                     iTotal += RandInt(1,4);     } } /* d6 Function  * This defines the six sided die  */ int d6(int iNumbr){     for(true;iNumbr;iNumbr--){                     srand(unsigned(time(NULL)));                     iTotal += RandInt(1,6);     } } /* d8 Function  * This defines the eight sided die  */ int d8(int iNumbr){     for(true;iNumbr;iNumbr--){                     srand(unsigned(time(NULL)));                     iTotal += RandInt(1,8);     } } /* d10 Function  * This defines the ten sided die  */ int d10(int iNumbr){     for(true;iNumbr;iNumbr--){                     srand(unsigned(time(NULL)));                     iTotal += RandInt(1,10);     } } /* d12 Function  * This defines the twelve sided die  */ int d12(int iNumbr){     for(true;iNumbr;iNumbr--){                     srand(unsigned(time(NULL)));                     iTotal += RandInt(1,12);     } } /* d20 Function  * This defines the twenty sided die  */ int d20(int iNumbr){     for(true;iNumbr;iNumbr--){                     srand(unsigned(time(NULL)));                     iTotal += RandInt(1,20);     } }  /* Main Function   * In the sceme of things this Fuction is merely a moderator   * no matter how puney, it ties the other functions togather   */ int Main(int iSides, int iTotal, int iNumbr){     cout << " \n  Dice Roller v1.!\n::::::::::::::::::::"  //Title and version         << "\n:::::How many dice are you going to Roll? "; //prompt # o' dice     cin >> iNumbr;    // input variable iNumbr     do{              // do{}while() loop           cout <<"\n:::::Alright! How many sides are on the dice?"//prompt sides             << " 4, 6, 8, 10, 12, or 20? ";                    //options           cin >> iSides;                                        //input iSides           if(iSides != 4 || iSides != 6 || iSides != 8 || iSides != 10  //if                 || iSides != 12 || iSides != 20){                      //user                           cout << "What? 4, 6, 8, 10, 12, or 20! \n"; //tamer           }else{            //else conditional for good users                 break;    //break loop           }              //   }while(true);        //   if(iSides==4){             d4(iNumbr);     }     if(iSides==6){             d6(iNumbr);     }     if(iSides==8){             d8(iNumbr);     }     if(iSides==10){               d10(iNumbr);     }     if(iSides==12){               d12(iNumbr);     }     if(iSides==20){               d20(iNumbr);     } }```
I keep getting a Linker Error, like the one below :::

Quote:

[Linker error] undefined reference to 'WinMain@16'
Id returned 1 exit status
Whats going on!!! ;_;
• 10-22-2007
brewbuck
You need to compile as a console app, not a Windows app.
• 10-22-2007
Daved
You need a function called main that specifies a return value of int. You have a function called Main. Case matters, so the linker cannot find main when you only have Main.

Also, the proper parameters for main are either none or int, char**. So I'd change it to this:
Code:

```int main() {   // code here }```
You use the parameters int iSides, int iTotal, int iNumbr, as if they were local variables. Those should be local variables in main, not function parameters.

>> You need to compile as a console app, not a Windows app.
This might be the problem, but I think the same error appears either way if you fail to provide an actual main.
• 10-23-2007
CornedBee
By the way, do you notice any similarity in your d* functions that can be exploited?
• 10-23-2007
Salem
You also call srand() WAY too many times. Enough times to ensure rand() returns the same value each time.

Once is enough, right at the start of main().