SFML community forums

Help => General => Topic started by: yj1214 on July 29, 2015, 02:02:34 am

Title: undefined reference to 'WinMain@16'
Post by: yj1214 on July 29, 2015, 02:02:34 am
*EDIT* oops, I accudently posted this in the wrong forum. Does anyone know how to remove or move this post to 'help general forum'? Thanks




I did everything right. I built SFML using Cmake with MSYS configuration. Then I copied exact code from the tutorial which looks like this,


Code: [Select]
#include <SFML/Window.hpp>


int mian(){
    sf::Window window(sf::VideoMode(500, 400), "Window", sf::Style::None);
   
   
    while(window.isOpen()){
        sf::Event event;
       
        while(window.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                window.close();
            }
        }
    }

    return 0;
}



This is my compilation...

Code: [Select]
g++ -std=c++11 window.cpp -o window.exe -L. -lsfml-main -lsfml-window -lsfml-
system

It gives me this error...

Code: [Select]
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.start
up+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make: *** [all] Error 1



What's my problem?
Title: AW: undefined reference to 'WinMain@16'
Post by: eXpl0it3r on July 29, 2015, 02:25:53 am
You link against sfml-main yet you don't set the sub-system to window. IIRC it's the flag -mwindow
Title: Re: undefined reference to 'WinMain@16'
Post by: yj1214 on July 29, 2015, 03:24:16 am
No effects...

Code: [Select]
g++ -std=c++11 window.cpp -o window.exe -L. -mwindows -lsfml-main -lsfml-window -lsfml-system
It gives me the same error...oh and is sfml-main necessary? what does it do?
Title: Re: undefined reference to 'WinMain@16'
Post by: AlexxanderX on July 29, 2015, 08:58:20 am
I don't know if is typo but in the code instead of "int main()" is "int mian()".
Title: Re: undefined reference to 'WinMain@16'
Post by: yj1214 on July 29, 2015, 09:45:35 am
Oh, um... *facepalm...I spent my whole day to find the bug and it was because I misspelled... guess I gotta learn how to spell things. Thanks for the solution!