Linker Error! Oh No!

This is a discussion on Linker Error! Oh No! within the C++ Programming forums, part of the General Programming Boards category; OK heres the deal see, I'm playing around with C++'s rand functions n' such, When I decide I want to ...

  1. #1
    Registered User gnimblegnome's Avatar
    Join Date
    Oct 2007
    FL, USA

    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:

     *          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--){
                        iTotal += RandInt(1,4);
    /* d6 Function
     * This defines the six sided die
    int d6(int iNumbr){
                        iTotal += RandInt(1,6);
    /* d8 Function
     * This defines the eight sided die
    int d8(int iNumbr){
                        iTotal += RandInt(1,8);
    /* d10 Function
     * This defines the ten sided die
    int d10(int iNumbr){
                        iTotal += RandInt(1,10);
    /* d12 Function
     * This defines the twelve sided die
    int d12(int iNumbr){
                        iTotal += RandInt(1,12);
    /* d20 Function
     * This defines the twenty sided die
    int d20(int iNumbr){
                        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);         //
    I keep getting a Linker Error, like the one below :::

    [Linker error] undefined reference to 'WinMain@16'
    Id returned 1 exit status
    Whats going on!!! ;_;

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    You need to compile as a console app, not a Windows app.

  3. #3
    Registered User
    Join Date
    Jan 2005
    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:
    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.
    Last edited by Daved; 10-22-2007 at 06:11 PM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    By the way, do you notice any similarity in your d* functions that can be exploited?
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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().
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker problem... no idea
    By cyreon in forum C Programming
    Replies: 2
    Last Post: 04-03-2009, 02:53 PM
  2. linker
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 02-23-2008, 12:25 AM
  3. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  4. Linker errors with Visual C++
    By codegirl in forum C++ Programming
    Replies: 4
    Last Post: 09-11-2003, 09:20 AM
  5. Compile with *.lib
    By Kelvin in forum C++ Programming
    Replies: 1
    Last Post: 07-23-2002, 06:24 PM

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