Pergunta

I'm using the following code (Allegro 4, C++), and getting the following error:

#include <allegro.h>

//defines
#define MODE GFX_SAFE
#define WIDTH 640
#define HEIGHT 480

int main (void)
{
    int ret;
    int counter;
    //initialize allegro
    allegro_init();
    install_keyboard();
    install_timer();
    srand(time(NULL));

    //set up screen
    //set video mode    
    ret = set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
    if (ret != 0)
        allegro_message(allegro_error);

        allegro_exit();
    return 0;
}

Error:

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

All the previous answers regarding that error tell me to switch to "Console" from "Windows"; but I already have "Console" in Properties->Linker->System->Subsystem.

If you don't have an answer, I'd be happy with something I could do to help narrow down the problem: I've used Allegro with C, but I want to use C++ to take advantage of OOP, and so I still have a lot of work to do.

Update:

#include <iostream>
#include <allegro.h>

using namespace std;


int main ()
{
    cout << "Hello World";
    return 0;

}

doesn't work, but

#include <iostream>

using namespace std;


int main ()
{
    cout << "Hello World";
    return 0;

}

does.

Now what? Answer: Start with Empty project.

Update2: restarted with an empty project, same code. First block (alleg.lib in linker, but allegro.h not included) works, second code (allegro.h included) doesn't. However, the bug is different:

1>LINK : fatal error LNK1561: entry point must be defined

What now?

Edit^2:Ignore all the following: I forgot to go back to including Allegro. It works now. Thanks everyone for the answers.

Edit: Adding:

END_OF_MAIN()

or

int END_OF_MAIN()

give the error "fatal error C1004: unexpected end-of-file found"

Foi útil?

Solução

You are getting the error because you are attempting to integrate allegro into a project that is non-empty.

You must create the project as an EMPTY PROJECT type:

New... > Project... > Visual C++ > Empty Project

--EDIT FOR SECOND ERROR--

You must append END_OF_MAIN() after the closing brace of int main():

int main() {
    //...
}
END_OF_MAIN()
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top