Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking Errors - unresolved external symbol _main....  (Read 5273 times)

0 Members and 1 Guest are viewing this topic.

Chipstix

  • Newbie
  • *
  • Posts: 6
    • View Profile
Linking Errors - unresolved external symbol _main....
« 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.

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #1 on: October 22, 2014, 06:58:58 pm »
Compile what? Post the code you are using.

Chipstix

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #2 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;
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking Errors - unresolved external symbol _main....
« Reply #3 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.
Laurent Gomila - SFML developer

Chipstix

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #4 on: October 22, 2014, 07:45:59 pm »
That's the thing, I have linked it to sfml-main..

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linking Errors - unresolved external symbol _main....
« Reply #5 on: October 22, 2014, 08:12:32 pm »
But you have not changed WinMain to the standard main.

Chipstix

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #6 on: October 22, 2014, 08:53:32 pm »
It still says the same thing with main.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking Errors - unresolved external symbol _main....
« Reply #7 on: October 22, 2014, 10:28:46 pm »
Show your updated code, and the corresponding error message.
Laurent Gomila - SFML developer

Chipstix

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #8 on: October 22, 2014, 11:41:31 pm »
It's exactly the same apart from its now main rather that WinMain.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Linking Errors - unresolved external symbol _main....
« Reply #9 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: AW: Linking Errors - unresolved external symbol _main....
« Reply #10 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking Errors - unresolved external symbol _main....
« Reply #11 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.
Laurent Gomila - SFML developer

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #12 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linking Errors - unresolved external symbol _main....
« Reply #13 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Chipstix

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Errors - unresolved external symbol _main....
« Reply #14 on: October 23, 2014, 03:05:52 pm »
My subsystem is set to windows too.. is there something I'm missing here?