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

Author Topic: Issues with using SFML with Visual Studio 2010  (Read 2254 times)

0 Members and 2 Guests are viewing this topic.

alphan95

  • Newbie
  • *
  • Posts: 4
    • View Profile
Issues with using SFML with Visual Studio 2010
« on: March 27, 2014, 02:42:33 am »
I get this error when I try to build it:
Quote
1>sfml-main-d.lib(SFML_Main.cpp.obj) : error LNK2019: unresolved external symbol _main referenced in function _WinMain@16
I followed the tutorial (http://www.sfml-dev.org/tutorials/2.1/start-vc.php). It's a windows application. I did change main to WinMain. I'm running in debug mode so I copied all the sfml-xxx-d.lib. Anybody can help?

TheCookie

  • Newbie
  • *
  • Posts: 1
  • I liek Cookies
    • View Profile
Re: Issues with using SFML with Visual Studio 2010
« Reply #1 on: March 27, 2014, 05:01:22 am »
If you created a Win32 application delete your whole code and put this.

#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
        RenderWindow window(VideoMode(200, 200), "Apocalypse");
        CircleShape shape(100.f);
        shape.setFillColor(Color::Green);

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

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

        return 0;
}
(I know using namespace sf; is bad but I'm testing stuff)

Then what you need to do is link all the libraries E.G, these are for release. Add the -d for debug.
sfml-main.lib
sfml-graphics.lib
sfml-audio.lib
sfml-system.lib
sfml-window.lib
sfml-network.lib

(Yet again, not the best way to do it since you're not using them, but I don't know what you move onto after this, you may need them)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Issues with using SFML with Visual Studio 2010
« Reply #2 on: March 27, 2014, 09:43:02 am »
Quote
1>sfml-main-d.lib(SFML_Main.cpp.obj) : error LNK2019: unresolved external symbol _main referenced in function _WinMain@16
[...] I did change main to WinMain.
When you combine the error message with that statement, you'll see that main() cannot be found by the linker, because you did not declare it.

Link to sfml-main and use main(), not WinMain(). This is explained in the tutorials, by the way...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

alphan95

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Issues with using SFML with Visual Studio 2010
« Reply #3 on: March 28, 2014, 12:24:09 am »
If you created a Win32 application delete your whole code and put this.

#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
        RenderWindow window(VideoMode(200, 200), "Apocalypse");
        CircleShape shape(100.f);
        shape.setFillColor(Color::Green);

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

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

        return 0;
}
(I know using namespace sf; is bad but I'm testing stuff)

Then what you need to do is link all the libraries E.G, these are for release. Add the -d for debug.
sfml-main.lib
sfml-graphics.lib
sfml-audio.lib
sfml-system.lib
sfml-window.lib
sfml-network.lib

(Yet again, not the best way to do it since you're not using them, but I don't know what you move onto after this, you may need them)
Didn't work. I get more errors


Quote
1>sfml-main-d.lib(SFML_Main.cpp.obj) : error LNK2019: unresolved external symbol _main referenced in function _WinMain@16
[...] I did change main to WinMain.
When you combine the error message with that statement, you'll see that main() cannot be found by the linker, because you did not declare it.

Link to sfml-main and use main(), not WinMain(). This is explained in the tutorials, by the way...
Tutorial says
Quote
If you chose to create a "Windows application" project, then the entry point of your code has to be the "WinMain" function instead of "main".


Doesn't look like anyone can fix this issue so I'm just going to try and use a different editor.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Issues with using SFML with Visual Studio 2010
« Reply #4 on: March 28, 2014, 12:56:00 am »
You have to read further.
Quote from: Tutorial
If you chose to create a "Windows application" project, then the entry point of your code has to be the "WinMain" function instead of "main". Since it's Windows specific, and your code would therefore not compile on Linux or Mac OS X, SFML provides a way to keep a standard "main" entry point in this case: link your project to the sfml-main module ("sfml-main-d.lib" in Debug, "sfml-main.lib" in Release), the same way you linked sfml-graphics, sfml-window and sfml-system.

Do not link to sfml-main and use WinMain. That's what I said in the last answer.

And please avoid full quotes, it makes the thread unreadable.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything