Thread: Multiple definition Error

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    Multiple definition Error

    hiya guys!
    I've been a "Lurker" for a while so i thought id come out of the C-Closet and as a Q thats been annoying me for a while..
    Im trying to install Allegro onto Windows, for use with Dev-Cpp.

    I try to comile/run this program, to see if its all good:

    Code:
    #include <stdio.h>
    #include <allegro.h>
    
    
    int main()
    {
        allegro_init();
        printf("allegro Version: %s\n", allegro_id);
        printf("ANY KEY DAMMIT!\n");
        system("pause");
        allegro_exit();
        return 0;
    }
    END_OF_MAIN()
    Yeah i was getting vexed, hence the printf

    The errors i get are:
    Code:
      multiple definition of `_mangled_main()' 
      first defined here 
      multiple definition of `WinMain@16' 
      first defined here 
      ld returned 1 exit status 
     C:\Dev-Cpp\Makefile.win [Build Error]  [Project1.exe] Error 1
    now i initially thought that there was more than lib file that had thrm inside, so on to project options... and i set -lalleg as the "linker"
    Same error unfortunatly

    So my Q would be...
    does anyone (maybe an Allegro Guru) know where the "defenition" of the statements in those errors are kept? Im hoping that once i know that i can delete any multple entries, or files.

    If anyone has come across this problem before, and knowws a solution, i would be really grateful for your help!

  2. #2
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    As an afterthought,
    That file is part of a project,
    the first file containing:

    Code:
    #include <allegro.h>
    
    int main (void)
    {
        allegro_init();
        set_gfx_mode(GFX_SAFE, 640,480,0,0);
        install_keyboard();
        textout_ex(screen, font, "Hello Dudes",1,1,10,-1);
        textout_ex(screen, font, "Press ESC key",1,12,11,-1);
        while(!key[KEY_ESC]);
        allegro_exit();
        return 0;
    }
    END_OF_MAIN()
    That compiles and runs ok, but im not sure if it will have a bearing on the 1st file.
    ive tried commenting out the headers in each of the files, but it just produces more errors (undefined)

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    So you're compiling a project with two main()'s and you're wondering why you have a problem?

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Ahh i see!
    I misunderstood how "projects" worked!
    thanks for clearing it up, makes a bit of sense now!

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Although saying that, i've now come across another problem...(Did i say problem.. i mean "unforseen challange")

    In trying to run the program detail in my second post, i get no errors generated, but also no output on the console window.

    a window appears, and just has "press any key to continue..." so itlooks like the only line its actually running is the system("pause"); one

    I tried to run it using a static library, and i get errors:

    Code:
      [Linker error] undefined reference to `_imp__allegro_id' 
      [Linker error] undefined reference to `_imp__allegro_error' 
      ld returned 1 exit status 
     C:\Dev-Cpp\Makefile.win [Build Error]  [Project1.exe] Error 1
    Last edited by Esqulax; 07-14-2007 at 03:00 AM.

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Are you properly linking with the allegro libraries? Looks like you're missing the needed specification of a .lib file.

  7. #7
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Thats a good idea.
    Im going by a book (from what i get .. mixed opinions of... Game Programming all in one)
    and set it up to the letter.
    I'll have a looksy at the Allegro thingy and see where these functions are kept.

    ::EDIT::
    I re-installed Allegro from the Devpaks, as people seemed to think this was a good idea.
    Tried it, but to no avail, same errors.
    Ive had a look at forums and suchlike but all i get is to make sure to #include <allegro.h>, i cant seem to find the library to link it to. Ive tried linking to -lalleg as i was advised to, and the console window appears and tells me merely to press any key to continue.

    when i change to the static libraries :
    Code:
    -lalleg_s
    -lgdi32
    -lwinmm
    -lole32
    -ldxguid
    -ldinput
    -lddraw
    -ldsound
    I start to get the above errors again.
    Maybe im just jinxed?
    Last edited by Esqulax; 07-14-2007 at 07:58 PM.

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Ok... progress...
    I THINK it may be the library file for the printfs thats not linked (If thats possible)
    as a test, i popped in the line:
    Code:
    allegro_message("Allegro version = &#37;s\n", allegro_id);
    which causes a message box to appear with the version number in. Im convinced that the allegro library is being looked at by the compiler.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I THINK it may be the library file for the printfs thats not linked (If thats possible)
    It's possible, but very unlikely . . . anyway, the standard library with C would be -lc and the standard C++ library would be -lc++. GCC (or g++) should automatically link with those. I seriously doubt that that's the problem.

    So what's happening? When you use printf(), you get an error message; but if you use allegro_message(), it works?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Right.. i'll srtart again

    My program as it is at the moment (Test prog to get everything working)

    Code:
    #include <stdio.h>
    #include <allegro.h>
    #include <string.h>
    
    int main()
    {
        allegro_init();
        set_gfx_mode(GFX_SAFE,640,480,0,0);
        textprintf_ex(screen,font,0,0,15,-1,
        "Allegro version = &#37;s\n", allegro_id);
        //printf("allegro Version: %s\n", allegro_id);
        //printf("ANY KEY DAMMIT!\n");
        system("pause");
        allegro_exit();
        return 0;
    }
    END_OF_MAIN()
    1)If i compile and run as is... it will compile, but on running, a window opens, then
    "Project2.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

    2)If i comment out the three lines below allegro_init(), and uncomment the printf's i get a blank window saying "Press any key to continue (Im guessing as a result of system("pause") and the printf's dont... print..f.

    3) however, if i add in
    Code:
    allegro_message("Allegro version = %s\n", allegro_id);
    BEFORE the textprintf the mesagebox appears (then so does a window, and problem 1 happens again)

    It all really is very strange!

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It seems your problem is that you have disabled the console window. If no console is created for the program, printf will have nowhere to print its message. system("pause") is a separate program and creates its own window.

    I think you may either need to create the project as a console program or find out how to enable the console.

    I guess system("pause") is not really a good way to keep GUI windows open. To simply block and wait for keyboard input, install_keyboard() and readkey().
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #12
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Ok.. ive gotten rid of system("pause"), and have put in install_keyboard(), the readkey(); at the bottom.. shuld have the same effect...
    but the inital problem is still occuring.

    I saet the project up as a console proj as oppsed to a GUI, and im getting the same prob also
    would my alleg42.dll be corrupt or something?

  13. #13
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Now, which of the problems?

    I have a problem terminating the program if I close the console window (and not pressing any key in allegro window). May-be you can solve this problem somehow, but if you are using allegro, then the console window would probably only be for yourself for debugging. So there might not be that much of a problem.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  14. #14
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    the 1st... "error has occured.. sorry were terminating your program"

    If it compiles and runs ok on your compy, it'll be my compiler settings then... but i cant think which one...

    Th closing console one.. im sure allegro, or even general C++ libs should have function that can allow/handle the x being hit, but thats a bridge in the distance

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM