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

Author Topic: Tutorial program won't link  (Read 2949 times)

0 Members and 1 Guest are viewing this topic.

Cedrei

  • Newbie
  • *
  • Posts: 3
    • View Profile
Tutorial program won't link
« on: March 05, 2017, 09:48:41 am »
I'm a total noob to SFML, I downloaded it an hour ago (I have the Visual C++ 14 (2015) - 64-bit in SFML 2.4.2) and went to test it by doing the first little code in the tutorial. I first tried to write it myself and then copy-pasting it, but nothing worked. I run on debug x64 in visual studio 2015, using these linker additional dependencies:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);sfml-audio-d.lib;sfml-graphics-d.lib;sfml-network-d.lib;sfml-system-d.lib;sfml-window-d.lib
If you don't feel like searching the tutorial for the code I'm talking about, it's here:
#include <SFML/Graphics.hpp>

int main()
{
        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;
}
And the error I got was LNK2019 in MSVCRTD.lib (exe_winmain.obj):
unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
 

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Tutorial program won't link
« Reply #1 on: March 05, 2017, 10:17:33 am »
sounds like you have subsystem (under linker settings) set to windows. Set it to console, or link to sfml-main (which internally provides a winmain() on windows platforms) if you dont want a console window to appear

Cedrei

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Tutorial program won't link
« Reply #2 on: March 05, 2017, 10:26:53 am »
That... helped, but now I get an error about sfml-system-d-2.dll not being on the computer. Where should I put that file for the program to find it?

Edit: If I used the static libraries, it works. Yay!  :D
« Last Edit: March 05, 2017, 10:30:24 am by Cedrei »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Tutorial program won't link
« Reply #3 on: March 05, 2017, 11:21:21 am »
The tutorial program would work if you took 5 minutes to read it carefully.

Quote
unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
Quote from: tutorial
If you chose to create a "Windows application" project, the entry point of your code has to be set to "WinMain" 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.

Quote
now I get an error about sfml-system-d-2.dll not being on the computer. Where should I put that file for the program to find it?
Quote from: tutorial
if you linked to the dynamic version of SFML, don't forget to copy the SFML DLLs (they are in <sfml-install-path/bin>) to the directory where your compiled executable is
Laurent Gomila - SFML developer

Cedrei

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Tutorial program won't link
« Reply #4 on: March 05, 2017, 12:00:58 pm »
Guess I am a fool, after all... D=

Well, thanks for taking your time to help a fool like me, I'm sorry to have bothered you.

caith

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Tutorial program won't link
« Reply #5 on: April 13, 2017, 05:07:04 am »
sounds like you have subsystem (under linker settings) set to windows. Set it to console, or link to sfml-main (which internally provides a winmain() on windows platforms) if you dont want a console window to appear

This was exactly my problem.  Thank you!