bloodshed compiler errors

This is a discussion on bloodshed compiler errors within the C++ Programming forums, part of the General Programming Boards category; EDIT: Sorry to edit so soon, but I went back after taking a break and solved 3 more of the ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    9

    Arrow wierd compiler error in bloodshed

    EDIT: Sorry to edit so soon, but I went back after taking a break and solved 3 more of the original 7 errors that stumped me. Now I got 4 left, and I am stumped again!

    Im testing myself and building a DOS game.

    Its a simple fight game, where the player contorls a character and the computer the other (using the simplest AI program ever ). It's based on choosing a random number, then doing an action based on where the number is (<50, do this thing, >50 do another thing, etc).

    Im getting errors, and I don't know why. I've included thesource code in my projec thats been bugging out, and the compile errores

    Source Code in Question(same GetRand(int,int) as from the tuts on this site, worked fine until today):

    #include <iostream>
    #include <stdlib.h>
    #include <ctime> //code from cprogramming.com

    int GetRand(int min, int max)
    {
    static int Init = 0;
    int rc;

    if (Init == 0)
    {
    /*
    * As Init is static, it will remember it's value between
    * function calls. We only want srand() run once, so this
    * is a simple way to ensure that happens.
    */
    srand(time(NULL));
    Init = 1;
    }

    /*
    * Formula:
    * rand() % N <- To get a number between 0 - N-1
    * Then add the result to min, giving you
    * a random number between min - max.
    */
    rc = (rand() % (max - min + 1) + min);

    return (rc);
    }
    Compile Errors:
    GetRand.cpp: In function `int GetRand(int, int)':
    GetRand.cpp:6: redefinition of `int GetRand(int, int)'
    GetRand.cpp:6: `int GetRand(int, int)' previously defined here
    GetRand.cpp:6: redefinition of `int GetRand(int, int)'
    GetRand.cpp:6: `int GetRand(int, int)' previously defined here
    Last edited by nerore; 04-16-2004 at 11:31 PM. Reason: figured out some stuff after 1st post, still have some errors

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,407
    The code compiles fine for me on Dev-C++ 4.9.8.7
    I had to add a main() function though, since you apparently forgot it.

    However, did you leave out any code?
    Try to copy and paste the code snippet, instead of re-writing it.

    Here's the code I tested with:
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    
    int GetRand(int min, int max)
    {
    	static int Init = 0;
    	int rc;
    
    	if (Init == 0)
    	{
    		/*
    		* As Init is static, it will remember it's value between
    		* function calls. We only want srand() run once, so this
    		* is a simple way to ensure that happens.
    		*/
    		srand(time(NULL));
    		Init = 1;
    	}
    
    	/*
    	* Formula:
    	* rand() % N <- To get a number between 0 - N-1
    	* Then add the result to min, giving you
    	* a random number between min - max.
    	*/
    	rc = (rand() % (max - min + 1) + min);
    
    	return (rc);
    }
    
    int main() {
    	std::cout<<GetRand(10, 20)<<std::endl;
    	std::cin.get(); //wait for dummy input
    	return 0;
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    9

    re:

    i added it as part of a project, not understanding the errors that came from it. I'll post the whole project now.

    I have a main function in another source, btw.
    Attached Files Attached Files

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,407
    1. Avoid spaces in your paths, Dev-C++ has an erratic problem with them.
    This means that a folder named "50 50 Combat" might cause problems, likewise if directories higher up have spaces in them.
    Likewise, you should not install Dev-C++ into a path containing spaces.

    2. In your main.cpp, there is:
    Code:
    #include "gameMenu.cpp"
    #include "driver.cpp"
    #include "userFuncs.cpp"
    #include "enemyFuncs.cpp"
    Since you already decided to place all function prototypes into funclist.h, do so.
    Do not #include .cpp files, at all.
    Rather, just compile them (separately, perhaps).
    During compilation and linking, the function prototypes in the .h file (or whatever relevant header file) will come into use, and then the object code generated from compiling the .cpp files with the actual functions will be used.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    9
    Thanks for the tips.

    EDIT: Fixed that problem. I had to re-reinstall it, so I must have made a mistake somewhere in the installation.

    BUT hehe, I still get an error. This time it is a linker, error.

    [Linker error] undefined reference to `userHealth'
    Heres the files if anyone wants to look at them.
    Attached Files Attached Files
    Last edited by nerore; 04-17-2004 at 02:21 PM. Reason: fixed problem myself, 2nd added my dev files for others to see

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    9
    okay, it compiles now...thanks for all your help, now I just have to do debugging ...gah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. Easiest 2D drawing library for bloodshed compiler?
    By thunderchief in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2005, 01:25 PM
  4. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 03:24 AM

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