Thread: [Linker error] undefined ref to winmain@16 HELP!!!

  1. #1
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121

    [Linker error] undefined ref to winmain@16 HELP!!!

    Hey all,
    Ok so i wasnt sure whether to put this in game programming or c++. So i put it here because it has little to do with the game more that im getting a linker error ever since i added my header file and implementation file. Here is the code....

    Code:
    // main
    #include <allegro.h>
    #include "game_essential.h"
    
    
    int main(int argc, char *argv[])
    {
        init();
        
        while(!key[KEY_ESC])
        ;
        
        deinit();
        return 0;
    }
    Code:
    // implementation
    #include "game_essential.h"
    
    void init(void)
    {
        allegro_init();
    	set_color_depth(32);
    	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
    	install_timer();
    	install_keyboard();
    	install_mouse();
    }
    
    void deinit(void)
    {
        clear_keybuf();
    }
    
    player::player(void)
    {
        x_speed = 0;
        y_speed = 0;
        hero = NULL;
    }
    
    level::level(void)
    {
        gravity = .7;
        thrust = .9;
        friction = .9333333;
    }
    
    int level::draw_scr(BITMAP *buf)
    {
        
    }
    
    int level::set_floor(BITMAP *floor)
    {
    }
    
    int level::set_background(BITMAP *bg)
    {
    }
    
    // -------- player
    
    int player::set_player(char *player_bmp)
    {
        hero = load_bitmap(player_bmp, NULL);
    }
    
    int player::draw_player(BITMAP *buffer)
    {
        draw_sprite(buffer, hero, x_real, y_real);
        return 1;
    }
    
    int player::check_pos(void)
    {
        // finish...    
    }
    
    int player::set_pos(level current)
    {
        
    }
    Code:
    // header
    #include <allegro.h>
    
    void init(void);
    void deinit(void);
    
    class level{
        public:
            level(void);
            int draw_scr(BITMAP *buf);
            int set_floor(BITMAP *floor);
            int set_background(BITMAP *bg);
            
        private:
            BITMAP *buffer;
            float gravity;
            float thrust;
            float friction;
    };
    
    class player{
        public: 
            player(void);
            int set_player(char *player_bmp); // set the player bitmap
            int draw_player(BITMAP *buffer); // draw player to bitmap
            int check_pos(void); // check collision ect
            int set_pos(level current); // set the position
            
        private: 
            BITMAP *hero; // our character
            float power;
            float x_speed;
            float y_speed;
            int x_real;
            int y_real;
    };
    Im using dev c++ with the latest updates and allegro files. Please help! :/ Thank you!

    -Mramazing
    -- Will you show me how to c++?

  2. #2
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Maybe you need to link the libraries you are using? You have to tell the compiler to link the .lib files. I'm not entirely sure, but I think that is usually what an Undefined Ref means.

    Good Luck

  3. #3
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    What i did was use dev's auto setup for allegro static apps and it links everything for me. It has always worked before... im jsut lost haha.
    -- Will you show me how to c++?

  4. #4
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Hmm, did you use WinMain() the last time it worked? Maybe you have to use it?

    I also found this in the FAQ, but I don't think it's your problem:
    http://www.bloodshed.net/dev/faq.html#winmain

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    int main indicates that you want to create Console application
    Missing WinMain indicates that you have created Windows Application - change the Project target
    Or create new project of teh correct type and import sources into it.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Allegro requires you to put a macro before or after your main() so it can mangle it around to something and produce code specific to your system... I don't remember which, and I certainly don't remember the details.

    Read the documentation like you're supposed to.

  7. #7
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    if you look at my code the function init() has the macros in it. Before you rudely give advice you should read the code. And secondly thank you Vart I will try that.
    -- Will you show me how to c++?

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I was referring to END_OF_MAIN(), which is not located in your code.

    You're an idiot. Go read the documentation.

    Edit: Here, just for you: http://www.allegro.cc/manual/api/usi...ro/end_of_main

  9. #9
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    Well i dont want to be called an idiot so go somewhere else if that is what you are going to do. Secondly you are right... END_OF_MAIN() is not there and it was the problem. I copied some of my code from a project that i did before and didnt copy END_OF_MAIN(). Assuming that there were no problems in my main.cpp i didnt even look there. So i will thank you for that. As far as calling me and idiot... screw you, i put the question there because i needed help. If i knew the answer there would be no question.

    - Cheers
    -- Will you show me how to c++?

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Well, let's see.

    1. You didn't read the documentation, at least not to the point of knowing what the problem was.
    2. You asked for help here, and was told what the problem was, namely that you were missing a macro that was supposed to go at the beginning or end of main(), and to read the documentation.
    3. You thought that reply was rude and ignored the solution that was given to you.
    4. After being spoonfed the solution along with an insult, you admitted the given answer was right, but yet you're still being combative.


    If this is how you think you're going to get help, you're wrong. Remember, everyone here, including myself, has better things to do than help you read documentation or help you remember what macro goes where. The least you could do is RTM before asking.

    Being a programmer is more than just being able to post on a forum or type out code. It's about problem solving, using the resources at your disposal in the best possible way. Having other programmers look up documentation for you is not the best way of handling either resource.

    I think you may need to read this: http://www.catb.org/~esr/faqs/smart-questions.html

  11. #11
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    If you have better things to do then go do them. I didnt ask you to look at the documentation, you did that on your own. If you are going to be a dick when you answer questions then dont help me. I dont want it or need it if you are going to be a dick. I would have figured out the problem sooner or later, with or without your help. Contrary to popular belief i have read the documentation i have used a lot of paper to print out the documentation and i do use it.

    So like i said before, if you have better things to do go do them instead of wasting your time on my questions.

    -Cheers
    -- Will you show me how to c++?

  12. #12
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    /me shrugs.

    As you wish.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    you look at my code the function init() has the macros in it. Before you rudely give advice you should read the code. And secondly thank you Vart I will try that.
    I think the thread went bad about here. MacGyver might have been a bit harsh with the read the docs comment but I cannot say that I don't agree with him. When you use an API like Allegro the docs should tell you how to go about programming under the API. If anything a quick google would have turned up a lot since this is probably a common beginner's problem.

    It's against the rules for anyone to intentionally flame or put some one down but I really don't feel that is what was intended here.

    Let's all play nice now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  3. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM