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

Author Topic: Setting up the SFML 2.1  (Read 1972 times)

0 Members and 1 Guest are viewing this topic.

stylequick

  • Newbie
  • *
  • Posts: 4
    • View Profile
Setting up the SFML 2.1
« on: November 07, 2014, 06:56:43 pm »
Hi,
I want to give a try to the SFML, but I'm having this issue while setting up on Visual Studio 2012 :

Quote
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: symbole externe non résolu _WinMain@16 référencé dans la fonction ___tmainCRTStartup

I'm getting this same error both with static and dynamic linking.

P.S : I read carefully the documentation.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Setting up the SFML 2.1
« Reply #1 on: November 07, 2014, 06:58:57 pm »
Is your project a "windows application" and not a "console application"?
If yes, you need to link sfml-main, as stated in the SFML & VS official tutorial.

stylequick

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Setting up the SFML 2.1
« Reply #2 on: November 07, 2014, 07:05:32 pm »
Thank you that worked.
But it is very strange since my project is a windows application and I'm not on Linux nor MAC.

But anyway, thank you.
« Last Edit: November 07, 2014, 07:45:30 pm by stylequick »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Setting up the SFML 2.1
« Reply #3 on: November 15, 2014, 08:14:51 pm »
It's not strange. It's Windows. :)

Your program needs a so-called entry point. It's a specific exported function that's called when the program is supposed to run. Once the function ends, the program ends as well.

Windows console programs follow the common pattern of calling this main entry point simply main(). So when you start a program, the operating system will look for an exported function main() and then call it (simplified).

Windows GUI applications (i.e. those without a console Window by default) use a different entry point: WinMain().

So if your Visual Studio project is set to be a console program, the linker will look for a function with the name main(). If you're building a GUI program, you'll need a WinMain(). The reason for the linker complaining about the missing reference is the added runtime, which will actually call the entry point defined by you.

What sfml-main provides is essentially a small wrapper. This static library includes a WinMain() that will try to call your actual main() function, essentially making cross-platform code (providing main() only) compile as a Windows application.