Hi, I have experience with C++ and the basics of SFML.
I would like to have MinGW and SFML on a USB Drive. What I've done is create a folder and moved all of the MinGW stuff to it. (C:/MinGW to the folder) Then, what I've done is download SFML 2.0 RC, the GCC DW2 version and extracted it. I put them both on the usb and start trying to get SFML to work, but I get a linking error.
I tried without using SFML, and compiling non-SFML related programs (such as the classic "Hello World!" program) and it worked fine. Only SFML (and possibly other ones too) doesn't work.
I try the following:
g++ test.cpp -ISFML/include/ -LSFML/lib/ -lsfml-graphics
and it gives me this error:
C:\Users\Joe\Desktop>g++ test.cpp -ISFML/include/ -LSFML/lib/ -lsfml-graphics
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x92): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x145): undefined reference to `_imp___ZN2sf6Window5closeEv'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x15d): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x1e3): undefined reference to `_imp___ZN2sf6Window7displayEv'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x1f2): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
c:/users/joe/desktop/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o: bad reloc address 0xe in section `.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]'
c:/users/joe/desktop/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Oh by the way, the reason why it says Desktop is because I'm testing it on the Desktop instead of the usb (it should work anyways, regardless of desktop or on usb stick.
I am running MSYS so I could easily change directories and then compile the code. Also, the code sample I'm using is:
#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;
}
Something is wrong when it's trying to link SFML. Also, I've redownloaded SFML GCC DW2 and MinGW multiple times, it's not that. I'm probably doing something wrong that I'm not realizing, hopefully someone could help me out.
If you have any questions, please ask, thanks.
I am such an idiot! What I was missing was "-lsfml-window". Which is weird, because on my linux computer, when I compile, all I needed was -lsfml-graphics and didn't need to add in window. Now my program compiles, but there's one thing doesn't work, the program itself. So I'm using the following:
g++ test.cpp -o sfml-app -ISFML/include/ -LSFML/lib/ -lsfml-graphics -lsfml-window -lsfml-system
This compiles my program. I also included the dll's that was required for the program to run, which are:
libgcc_s_dw2-1.dll
libstdc++-6.dll
sfml-graphics-2.dll
sfml-system-2.dll
sfml-window-2.dll
However, when running the program, it just crashes immediately and says: "sfml-app.exe has stopped working. Windows can check online for a solution to the problem."
Can someone enlighten me on this? Thanks.
And can you tell me how I can go about setting the subsystem to windows instead of console and then link against sfml main?
If you go with the terminal directly, then you'll have to add the compile flag: -mwindows and the linker flag lsfml-main.
So in the end your complete command would look like:
g++ test.cpp -o sfml-app -mwindows -ISFML/include/ -LSFML/lib/ -lsfml-graphics -lsfml-window -lsfml-system -lsfml-main
Btw. for the debug version, you'll also have to link against the debug SFML libraries (the ones with the suffix -d).