1
\$\begingroup\$

I have been having trouble linking sfml to qt creator I have downloaded the pre-compiled libraries and headers for MINGW on the sfml website here : http://www.sfml-dev.org/download/sfml/2.3.2/

This is my .pro file

QT       += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = SFML_MapEditor
TEMPLATE = app


SOURCES += main.cpp\
        MainWindow.cpp

HEADERS  += MainWindow.h

FORMS    += MainWindow.ui

INCLUDEPATH += "C:\VsIncludes\SFML\SFML-2.3.2\include"
DEPENDPATH += "C:\VsIncludes\SFML\SFML-2.3.2\include"

LIBS += -LC:\VsIncludes\SFML\SFML_QT\SFMLLIBS\

CONFIG(debug, release|debug): LIBS += -lsfml-window-d -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-system-d -lsfml-network-d
CONFIG(release, release|debug): LIBS += -lsfml-window -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-system -lsfml-network

Here is the project files where the binaries are read

The executable files

Now my problem lies in the loadFromFile() function. When I do run the program with the loadFromFile() function it will immediately give me this error:

C:\Users\Alex\Documents\QT_Projects\SFML_MapEditor\main.cpp:14: error: undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'

However when I run the program without loadFromFile() it will run without a hitch

My main.cpp file

#include "MainWindow.h"
#include <iostream>
#include <QApplication>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <QDebug>

void SFML_Test()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "HELLO SFML");

    sf::Texture tex;

    if (!tex.loadFromFile("Default_Texture.png"))
    {
        return;
    }

    sf::Sprite sprite(tex);

    while (window.isOpen())
    {
        sf::Event e;

        while (window.pollEvent(e))
        {
            if (e.type == sf::Event::Closed)
            {
                window.close();
            }
        }

        window.clear();
        window.draw(sprite);
        window.display();
    }
}


int main(int argc, char *argv[])
{
    /*
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
    */

    SFML_Test();

    return 0;
}
\$\endgroup\$
3
  • \$\begingroup\$ I have done further testing and it is only the loadFromFile function that will create this error in both the image class and texture class \$\endgroup\$ Commented Jun 13, 2016 at 22:14
  • \$\begingroup\$ I fixed my .pro file however I still get the undefined function reference from loadFromFile \$\endgroup\$ Commented Jun 14, 2016 at 1:31
  • \$\begingroup\$ Another thing, I have built the libraries with my version of mingw \$\endgroup\$ Commented Jun 14, 2016 at 2:07

1 Answer 1

1
\$\begingroup\$

Turns out that I was using sfml 2.3.2 which I guess isn't fully compatible with qt creator so I tried sfml 2.0 and it suddenly worked.

Here is a link to a video describing how to link SFML to Qt Creator: https://www.youtube.com/watch?v=VWvD4mUpyfU

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.