SFML community forums

Help => General => Topic started by: Lamonte on July 19, 2013, 07:23:54 pm

Title: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 19, 2013, 07:23:54 pm
So I'm trying to compile on windows using g++ and I get a few errors, not sure what I'm doing wrong.

Quote
C:\Users\Lamonte\Documents\Project\C++>g++ main.cpp -Ic:\SFML-2.0\include
In file included from c:\SFML-2.0\include\SFML/System.hpp:34,
                 from c:\SFML-2.0\include\SFML/Window.hpp:32,
                 from c:\SFML-2.0\include\SFML/Graphics.hpp:32,
                 from main.cpp:1:
c:\SFML-2.0\include\SFML/System/Err.hpp:32: ostream: No such file or directory
In file included from c:\SFML-2.0\include\SFML/System.hpp:39,
                 from c:\SFML-2.0\include\SFML/Window.hpp:32,
                 from c:\SFML-2.0\include\SFML/Graphics.hpp:32,
                 from main.cpp:1:
c:\SFML-2.0\include\SFML/System/String.hpp:32: locale: No such file or directory

In file included from c:\SFML-2.0\include\SFML/System.hpp:43,
                 from c:\SFML-2.0\include\SFML/Window.hpp:32,
                 from c:\SFML-2.0\include\SFML/Graphics.hpp:32,
                 from main.cpp:1:
c:\SFML-2.0\include\SFML/System/Utf.hpp:33: locale: No such file or directory

Source: main.cpp
#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;
}
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Laurent on July 19, 2013, 07:46:50 pm
Standard headers are not found, your compiler seems to be broken. No matter what code you write, you won't be able to compile it until you fix your compiling environment.
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 19, 2013, 08:27:50 pm
So i've reinstalled MingW on windows  (http://sourceforge.net/projects/mingw/?source=dlp)

Source: main.cpp
#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }

    return 0;
}

Ran: g++ -c main.cpp -Ic:\SFML-2.0\include -> main.o file was created.

Now when I go to do: g++ main.o -o sfml-app -Lc:\SFML-2.0\lib -lsfml-window -lsfml-system

I get a weird error:

Quote
C:\Users\Lamonte\Documents\Project\C++>g++ main.o -o sfml-app -Lc:\SFML-2.0\lib
 -lsfml-window -lsfml-system
main.o:main.cpp:(.text+0xd1): undefined reference to `_imp___ZN2sf6StringC1EPKcR
KSt6locale'
main.o:main.cpp:(.text+0xf7): undefined reference to `_imp___ZN2sf9VideoModeC1Ej
jj'
main.o:main.cpp:(.text+0x132): undefined reference to `_imp___ZN2sf6WindowC1ENS_
9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
main.o:main.cpp:(.text+0x162): undefined reference to `_imp___ZN2sf6Window5close
Ev'
main.o:main.cpp:(.text+0x178): undefined reference to `_imp___ZN2sf6Window9pollE
ventERNS_5EventE'
main.o:main.cpp:(.text+0x18a): undefined reference to `_imp___ZNK2sf6Window6isOp
enEv'
main.o:main.cpp:(.text+0x1a1): undefined reference to `_imp___ZN2sf6WindowD1Ev'
main.o:main.cpp:(.text+0x1cf): undefined reference to `_imp___ZN2sf6WindowD1Ev'
main.o:main.cpp:(.text+0x1f9): undefined reference to `_imp___ZN2sf6WindowD1Ev'
collect2: ld returned 1 exit status
Title: AW: Trying to compile SFML from the command line using g++ on windows
Post by: eXpl0it3r on July 19, 2013, 09:34:50 pm
Have you #define SFML_STATIC somewhere in your code?
IIRC _imp__ referrs to static symbols.
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 19, 2013, 10:19:03 pm
I haven't.
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Laurent on July 19, 2013, 10:21:57 pm
Quote
IIRC _imp__ referrs to static symbols.
imp -> imported -> dynamic ;)
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 19, 2013, 10:26:13 pm

Quote
C:\Users\Lamonte\Documents\Project\C++>g++ main.o -o main.exe -Lc:\SFML-2.0\lib
-lsfml-system -lsfml-window

main.o:main.cpp:(.text+0xd1): undefined reference to `sf::String::String(char co
nst*, std::locale const&)'
main.o:main.cpp:(.text+0xf5): undefined reference to `sf::VideoMode::VideoMode(u
nsigned int, unsigned int, unsigned int)'
main.o:main.cpp:(.text+0x12e): undefined reference to `sf::Window::Window(sf::Vi
deoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.o:main.cpp:(.text+0x15c): undefined reference to `sf::Window::close()'
main.o:main.cpp:(.text+0x170): undefined reference to `sf::Window::pollEvent(sf:
:Event&)'
main.o:main.cpp:(.text+0x180): undefined reference to `sf::Window::isOpen() cons
t'
main.o:main.cpp:(.text+0x195): undefined reference to `sf::Window::~Window()'
main.o:main.cpp:(.text+0x1c1): undefined reference to `sf::Window::~Window()'
main.o:main.cpp:(.text+0x1e9): undefined reference to `sf::Window::~Window()'
collect2: ld returned 1 exit status

Quote
C:\Users\Lamonte\Documents\Project\C++>g++ main.o -o main.exe -Lc:\SFML-2.0\lib
-lsfml-system-s -lsfml-window-s

main.o:main.cpp:(.text+0xd1): undefined reference to `sf::String::String(char co
nst*, std::locale const&)'
main.o:main.cpp:(.text+0xf5): undefined reference to `sf::VideoMode::VideoMode(u
nsigned int, unsigned int, unsigned int)'
main.o:main.cpp:(.text+0x12e): undefined reference to `sf::Window::Window(sf::Vi
deoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.o:main.cpp:(.text+0x15c): undefined reference to `sf::Window::close()'
main.o:main.cpp:(.text+0x170): undefined reference to `sf::Window::pollEvent(sf:
:Event&)'
main.o:main.cpp:(.text+0x180): undefined reference to `sf::Window::isOpen() cons
t'
main.o:main.cpp:(.text+0x195): undefined reference to `sf::Window::~Window()'
main.o:main.cpp:(.text+0x1c1): undefined reference to `sf::Window::~Window()'
main.o:main.cpp:(.text+0x1e9): undefined reference to `sf::Window::~Window()'
collect2: ld returned 1 exit status

I've tried adding #define SFML_STATIC to the top of the cpp file and instead of it not properly outputting the error its showing the above now.

Just trying to get this to work so I can setup a proper build command for my sublime text editor to compile via sublime text 2.  Wonder if it's my MingW :/
Title: AW: Re: Trying to compile SFML from the command line using g++ on windows
Post by: eXpl0it3r on July 19, 2013, 10:30:29 pm
:(.t
I've tried adding #define SFML_STATIC to the top of the cpp file and instead of it not properly outputting the error its showing the above now.
No don't do that!
I was mistaken, see Laurents post! :-[
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 19, 2013, 10:35:21 pm
Alright removed it, still no idea what's wrong.  It's definitely a linker issue though from what I'm understanding.
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 20, 2013, 03:01:56 am
I guess no one knows what's wrong with my issue, unfortunately I've tried everything that I could think of.

Well can someone explain to me how I can compile SFML from the command line properly on windows 7?
Title: Re: Trying to compile SFML from the command line using g++ on windows
Post by: Lamonte on July 20, 2013, 05:12:05 am
Okay I fixed it.  I had to rebuild SFML w/ my version of MingW (following this guide http://sfmlcoder.wordpress.com/2011/06/16/building-sfml-2-0-with-mingw-make/) and everything worked.  I knew I wasn't crazy.