SFML community forums

Help => General => Topic started by: Chipstix on October 22, 2014, 06:43:36 pm

Title: Linking Errors - unresolved external symbol _main....
Post by: Chipstix on October 22, 2014, 06:43:36 pm


Every time I compile I get this error.. Can't find a solution to the problem..

error LNK2019: unresolved external symbol _main referenced in function _WinMain@16   

Thanks.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Gambit on October 22, 2014, 06:58:58 pm
Compile what? Post the code you are using.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Chipstix on October 22, 2014, 07:12:51 pm
Oops, I thought I said. Im compiling the tutorial code :
#include <SFML/Graphics.hpp>

int WinMain()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Laurent on October 22, 2014, 07:23:05 pm
Use main() as the entry point of your application. If you created a Win32 GUI application that expects WinMain, link to sfml-main as stated in the tutorial.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Chipstix on October 22, 2014, 07:45:59 pm
That's the thing, I have linked it to sfml-main..
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Jesper Juhl on October 22, 2014, 08:12:32 pm
But you have not changed WinMain to the standard main.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Chipstix on October 22, 2014, 08:53:32 pm
It still says the same thing with main.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Laurent on October 22, 2014, 10:28:46 pm
Show your updated code, and the corresponding error message.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Chipstix on October 22, 2014, 11:41:31 pm
It's exactly the same apart from its now main rather that WinMain.
Title: AW: Linking Errors - unresolved external symbol _main....
Post by: eXpl0it3r on October 23, 2014, 08:14:53 am
If you link against sfml-main you need to set the subsystem to "window", otherwise it should be "console".
In both cases "int main()" is the entry point.

Make sure to do a clean rebuild.
Title: Re: AW: Linking Errors - unresolved external symbol _main....
Post by: Gambit on October 23, 2014, 08:57:15 am
If you link against sfml-main you need to set the subsystem to "window", otherwise it should be "console".

You do not need to change the subsystem if you link to sfml-main. I have projects linking to main which run in both Console and System and I have no issues.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Laurent on October 23, 2014, 09:41:18 am
Quote
You do not need to change the subsystem if you link to sfml-main. I have projects linking to main which run in both Console and System and I have no issues.
You can link to sfml-main in a console project, yes, but it is completely useless since the linker won't use the WinMain entry point that it defines.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Gambit on October 23, 2014, 10:35:34 am
Does sfml-main have any other purpose? The dependency is listed in a property sheet so I cant tell it not to include it for console projects.
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: eXpl0it3r on October 23, 2014, 10:40:13 am
sfml-main does one thing only, for Windows it looks like this:

#include <SFML/Config.hpp>

#ifdef SFML_SYSTEM_WINDOWS

#include <windows.h>


extern int main(int argc, char* argv[]);

////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
    return main(__argc, __argv);
}

#endif // SFML_SYSTEM_WINDOWS
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: Chipstix on October 23, 2014, 03:05:52 pm
My subsystem is set to windows too.. is there something I'm missing here?
Title: Re: Linking Errors - unresolved external symbol _main....
Post by: eXpl0it3r on October 23, 2014, 03:24:29 pm
Did you add the file containing your main function to the project?
The linker can only find the main function if it has been compiled and is provided to the linker.