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

Author Topic: Build SFML 2.1 Program From MinGW  (Read 2669 times)

0 Members and 1 Guest are viewing this topic.

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Build SFML 2.1 Program From MinGW
« on: May 02, 2014, 12:05:45 am »
Here's the situation: I'm on the heels of finishing an IDE which is somewhat of a gift to my high school CS teacher. One of the very last, and admittedly most important features of the IDE, is the ability to compile an SFML project. Currently I'm trying to get SFML to simply compile from the command prompt. These are the locations of my resources:

  • main.cpp (see source below) - C:\Users\Quinn McHugh\Desktop\test\main.cpp (Nothing else in this folder)
  • MinGW (unmodified lib/ and include/ directories) - C:\MinGW\include\c++\3.4.5 (this is in my path variable)
  • SFML 2.1 - C:\SFML-2.1

First what I do is navigate to the folder titled test inside the command prompt, next I type the command "g++ -c -IC:\SFML-2.1\include main.cpp". As far as I can tell, this compiles without issue and produces the file main.o. Next is where the problems appear. I now try to link this whole project together with the command "g++ main.o -o main.exe -LC:\SFML-2.1\lib -DSFML_STATIC -lsfml-graphics -lsfml-window -lsfml-system", and I get these errors:

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
 

main.cpp:
#include <SFML/Window.hpp>
int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }
    return 0;
}
 

What must I change to successfully be able to run this sfml project?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Build SFML 2.1 Program From MinGW
« Reply #1 on: May 02, 2014, 12:08:09 am »
My guess would be change the link order to system, window, graphics, because graphics depends on window and window depends on system.

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Build SFML 2.1 Program From MinGW
« Reply #2 on: May 02, 2014, 12:12:07 am »
I just tried switching the order to system, window, graphics and I got the identical error messages.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Build SFML 2.1 Program From MinGW
« Reply #3 on: May 02, 2014, 12:14:44 am »
Oh, I think for static linking you need to link the -s versions of the libs.

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Build SFML 2.1 Program From MinGW
« Reply #4 on: May 02, 2014, 12:25:27 am »
I just tried "g++ main.o -o main.exe -LC:\SFML-2.1\lib -DSFML_STATIC -lsfml-system-s -lsfml-window-s -lsfml-graphics-s" and I got the same ream of errors.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Build SFML 2.1 Program From MinGW
« Reply #5 on: May 02, 2014, 12:31:01 am »
Are you sure these are the right versions of the libraries?  That these were compiled with the same exact compiler you're currently using?

I guess you could also try a one-step build straight from .cpp to .exe.  Or attempt dynamic linking and see if that's any easier.  I can't think of any other reason this would fail.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Build SFML 2.1 Program From MinGW
« Reply #6 on: May 02, 2014, 12:33:54 am »
Is there a reason you want to link SFML statically?

You had the correct order in the first place, it's graphics, window and system (graphics depends on window which depends on system).

If you want to use the static version of SFML you need to use the libraries with the -s suffix. Also read this.
When you change something, make sure to run a clean rebuild.

Where did you get SFML from? Did you build it from source with the same compiler?
The 3.4.5 of you MinGW installation kind of worries me, because if you're still using GCC 3.4.5 then you should really upgrade. The latest version is either 4.8 or 4.9. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Build SFML 2.1 Program From MinGW
« Reply #7 on: May 02, 2014, 12:50:45 am »
@Ixrec I re-downloaded the 32 bit gcc version of SFML just to be safe and there was no difference, so I guess I had the correct version to start with.

@eXpl0it3r There is no reason I am linking statically, it's just the way I saw it being done. Also, do you think it should really matter if I download the latest version of MinGW? I feel like my issues are related to something else.

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Build SFML 2.1 Program From MinGW
« Reply #8 on: May 02, 2014, 01:56:48 am »
Ok, I have a recent development. I removed the static requests from the command changing it to "g++ main.o -o main.exe -LC:\SFML-2.1\lib -lsfml-system -lsfml-window -lsfml-graphics" and it created an .exe! Once I put the .dll's into the same directory, I ran the .exe and got an error from windows saying "main.exe has stopped working. Windows is checking for a solution to the problem". Any suggestions? I feel like I'm getting really close!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Build SFML 2.1 Program From MinGW
« Reply #9 on: May 02, 2014, 09:12:39 am »
Not sure how it linked, given that the order is still wrong. It's graphics, window, system.

Your compiler has to match the compiler with which the binaries were built, otherwise it won't work. At best you grab the latest release version of the MinGW Builds and rebuild SFML from source by following the official tutorial.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything