SFML - Undefined reference to 'WinMain@16'

I'm trying to use SFML to make a game, but I ran into an error. I have 4 files in my project: main.cpp, Screen.cpp, Screen.h, and GameState.h. I built them individually and the only one with an error is Screen.cpp. The error reads "undefined reference to `WinMain@16'". Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <SFML/Window.hpp>
#include "Screen.h"

using namespace sf;

void Screen::showSplash(sf::RenderWindow &window)
{
    Image imgSplash;
    if(imgSplash.LoadFromFile("images/Splash.png") == false)
    {
        return;
    }

    Sprite splash(imgSplash);
    window.Draw(splash);
    window.Display();

    Event currentEvent;
    while(true)
    {
        window.GetEvent(currentEvent);
        if(currentEvent.Type == Event::KeyPressed
        || currentEvent.Type == Event::MouseButtonPressed
        || currentEvent.Type == Event::Closed)
        {
            return;
        }
    }
}


And in case it's important, here's Screen.h:

1
2
3
4
5
6
7
8
9
10
11
12
#ifndef SPLASH_H_INCLUDED
#define SPLASH_H_INCLUDED

#include <SFML/Graphics.hpp>

class Screen
{
public:
    void showSplash(sf::RenderWindow &window);
};

#endif // SPLASH_H_INCLUDED 


Thanks in advance.
Last edited on
You need to link to sfml-main.lib (or sfml-main-d.lib), I think.
Seems that your build is expecting screen.cpp to be turned into a stand-alone windows executable program. I'm guessing that's not what you want.

Make sure your project is whatever Visual Studio uses these days to mean a console program with a regular, simple int main() entry point. Building them separately is flawed - they need to be linked together to make the complete, working program, and if you don't know how to take object files and manually link them together to make a single executable, you're creating more work for yourself. Put them into the project and have VS build them for you.
Last edited on
@Moschops: Oh, I guess that's because I built it individually to troubleshoot. Originally the error was "undefined reference to 'Screen::showSplash(sf::RenderWindow&)'", and I wanted to see if I made a mistake in Screen.cpp. I call it like this:

1
2
3
4
5
6
7
8
9
10
11
Screen screen;
switch(gameState)
{
case ShowingSplash:
      screen.showSplash(mainWnd);
break;
case Playing:
      mainWnd.Clear(Color(255, 255, 255));
      mainWnd.Display();
break;
}


I couldn't find any reason for why that would give me an error, so I built Screen.cpp individually.

EDIT: I use Code::Blocks by the way.
Last edited on
Uhh... it seems to have fixed itself... so, thanks for the help!
Last edited on
Topic archived. No new replies allowed.