Bienvenue, Invité. Merci de vous connecter ou de vous inscrire.
Avez-vous perdu votre e-mail d'activation ?

Auteur Sujet: Compilation avec QtCreator : undefined reference to  (Lu 2018 fois)

0 Membres et 1 Invité sur ce sujet

djentx

  • Newbie
  • *
  • Messages: 5
    • Voir le profil
Compilation avec QtCreator : undefined reference to
« le: Janvier 02, 2014, 03:49:28 pm »
Ceci est un regroupement de deux post que j'avais dans une mauvaise section.

Bonjour,
j'essaie de suivre le tuto sur la manière d’intégrer SFML dans une fenêtre Qt.
J'ai essayé d'adapter le tuto a SFML2.1 et Qt 5.2.0, j'ai recompilé les sources de la SFML2.1 avec mingw fournit dans Qt5.2.0.

L'adaptation s'est plutôt bien passée mais j'ai visiblement un problème avec qmake.

mon fichier.pro:
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = qtsfml
TEMPLATE = app


SOURCES += main.cpp\
    qsfmlcanvas.cpp \
    mycanvas.cpp

HEADERS  += \
    qsfmlcanvas.h \
    mycanvas.h

FORMS    +=

LIBS += -LC:C:/SFML-2.1-build/lib

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

INCLUDEPATH += C:/SFML-2.1/include
DEPENDPATH += C:/SFML-2.1/include

lorsque je compile, il me dit:
cannot find -libsfml-xxx (une erreur pour chaque lib de la liste de la config utilisée (debug / release)).

Tout les libsfml-xxx.a sont biens dans C:/SFML-2.1-build/lib.

Si vous pouviez m'aider...

Merci d'avance

-------------------------------------------------------------


Bon après avoir longtemps chercher et relu le tuto https://github.com/SFML/SFML/wiki/Tutorial%3A-Compile-and-Link-SFML-with-Qt-Creator

je me suis appercu d'une erreur

LIBS += -LC:C:/SFML-2.1-build/lib

aurait du etre

LIBS += -LC:/SFML-2.1-build/lib

et est devenu

LIBS += -LC:/SFML/SFML-2.1-build/lib

car j'ai rangé mes dossier.

Mais le probleme reste le meme, donc dans le doute (et dans l'un de mes tres nombreux essais) j'ai remplacé les -libsfml-xxx par des lsfml-xxx comme dans le tuto.

Les erreurs cannot find ont disparue pour laisser place a

debug/mycanvas.o: In function `ZN8MyCanvasC2EP7QWidgetRK6QPointRK5QSize':
C:\projets\projetsQt5\qtsfml/mycanvas.cpp:4: undefined reference to `QSFMLCanvas::~QSFMLCanvas()'

debug/mycanvas.o: In function `ZN8MyCanvasD1Ev':
C:\projets\projetsQt5\qtsfml/mycanvas.h:8: undefined reference to `QSFMLCanvas::~QSFMLCanvas()'

C:\projets\projetsQt5\qtsfml/mycanvas.h:8: undefined reference to `QSFMLCanvas::~QSFMLCanvas()'
Makefile.Debug:82: recipe for target '
debug\qtsfml.exe' failed
mingw32-make[1]: Leaving directory '
C:/projets/projetsQt5/qtsfml'
makefile:34: recipe for target '
debug' failed
debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0x14): undefined reference to `QSFMLCanvas::~QSFMLCanvas()'

debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0x18): undefined reference to `QSFMLCanvas::~QSFMLCanvas()'
debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0xd8): undefined reference to `QSFMLCanvas::OnInit()'

debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0xdc): undefined reference to `QSFMLCanvas::OnUpdate()'
debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0xe8): undefined reference to `non-virtual thunk to QSFMLCanvas::~QSFMLCanvas()'

debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0xec): undefined reference to `non-virtual thunk to QSFMLCanvas::~QSFMLCanvas()'
debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0x110): undefined reference to `non-virtual thunk to QSFMLCanvas::~QSFMLCanvas()'

debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0x114): undefined reference to `non-virtual thunk to QSFMLCanvas::~QSFMLCanvas()'
debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0x130): undefined reference to `non-virtual thunk to QSFMLCanvas::~QSFMLCanvas()'

debug/moc_qsfmlcanvas.o:moc_qsfmlcanvas.cpp:(.rdata$_ZTV11QSFMLCanvas[__ZTV11QSFMLCanvas]+0x134): undefined reference to `non-virtual thunk to QSFMLCanvas::~QSFMLCanvas()'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [debug\qtsfml.exe] Error 1
mingw32-make: *** [debug] Error 2
23:44:01: Le processus "C:\Qt\Qt5.2.0\Tools\mingw48_32\bin\mingw32-make.exe" s'
est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet qtsfml (kit : Desktop Qt 5.2.0 MinGW 32bit)
Lors de l'exécution de l'étape "Make"

J'ai beau chercher dans le code je ne vois pas le problème.
Le code est issu du tuto http://www.sfml-dev.org/tutorials/1.6/graphics-qt-fr.php

Merci d'avance.

Le .pro
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = qtsfml
TEMPLATE = app


SOURCES += main.cpp\
    qsfmlcanvas.cpp \
    mycanvas.cpp

HEADERS  += \
    qsfmlcanvas.h \
    mycanvas.h

FORMS    +=

LIBS += -LC:/SFML/SFML-2.1-build/lib

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



INCLUDEPATH += C:/SFML/SFML-2.1/include
DEPENDPATH += C:/SFML/SFML-2.1/include

le main:
#include "widget.h"
#include "mycanvas.h"
#include <QApplication>
#include <QFrame>

int main(int argc, char **argv)
{
    QApplication App(argc, argv);

    // On crée la fenêtre principale
    QFrame* MainFrame = new QFrame;
    MainFrame->setWindowTitle("Qt SFML");
    MainFrame->resize(400, 400);
    MainFrame->show();

    //On crée une vue SFML dans la fenêtre principale
    MyCanvas* SFMLView = new MyCanvas(MainFrame, QPoint(20, 20), QSize(360, 360));
    SFMLView->show();

    return App.exec();
}

qsfmlcanvas.h
#ifndef QSFMLCANVAS_H
#define QSFMLCANVAS_H

#include <QWidget>
#include <SFML/Graphics.hpp>
#include <QTimer>

class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
    Q_OBJECT
public :

    QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0);

    virtual ~QSFMLCanvas();

private :

    virtual void OnInit();

    virtual void OnUpdate();

    virtual QPaintEngine* paintEngine() const;

    virtual void showEvent(QShowEvent*);

    virtual void paintEvent(QPaintEvent*);

    QTimer myTimer;
    bool   myInitialized;

};

#endif // QSFMLCANVAS_H
 

qsfmlcanvas.cpp
#include "qsfmlcanvas.h"

QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
QWidget       (Parent),
myInitialized (false)
{
    // Mise en place de quelques options pour autoriser le rendu direct dans le widget
    setAttribute(Qt::WA_PaintOnScreen);
    setAttribute(Qt::WA_OpaquePaintEvent);
    setAttribute(Qt::WA_NoSystemBackground);

    // Changement de la police de focus, pour autoriser notre widget à capter les évènements clavier
    setFocusPolicy(Qt::StrongFocus);

    // Définition de la position et de la taille du widget
    move(Position);
    resize(Size);

    // Préparation du timer
    myTimer.setInterval(FrameTime);
}


void QSFMLCanvas::showEvent(QShowEvent*)
{
    if (!myInitialized)
    {
        // On crée la fenêtre SFML avec l'identificateur du widget
        sf::Window::create(reinterpret_cast<sf::WindowHandle>(winId()));

        // On laisse la classe dérivée s'initialiser si besoin
        OnInit();

        // On paramètre le timer de sorte qu'il génère un rafraîchissement à la fréquence souhaitée
        connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
        myTimer.start();

        myInitialized = true;
    }
}

QPaintEngine* QSFMLCanvas::paintEngine() const
{
    return 0;
}

void QSFMLCanvas::paintEvent(QPaintEvent*)
{
    // On laisse la classe dérivée faire sa tambouille
    OnUpdate();

    // On rafraîchit le widget
    display();
}
 

mycanvas.h
#ifndef MYCANVAS_H
#define MYCANVAS_H

#include "qsfmlcanvas.h"
#include <QWidget>
#include <SFML/Graphics.hpp>

class MyCanvas: public QSFMLCanvas
{
public:
    MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size);

private:
    void OnInit();
    void OnUpdate();

    sf::Texture  myTexture;
    sf::Sprite mySprite;
};

#endif // MYCANVAS_H
 

mycanvas.cpp
#include "mycanvas.h"

MyCanvas::MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) :
    QSFMLCanvas::QSFMLCanvas(Parent, Position, Size)
{

}


void MyCanvas::OnInit()
{
    // On charge une image
    myTexture.loadFromFile("C:/SFML-2.1/examples/shader/resources/sfml.png");

    // On paramètre le sprite
    mySprite.setTexture(myTexture);

    sf::FloatRect rectf = mySprite.getLocalBounds();
    mySprite.setOrigin(rectf.width/2.0, rectf.height/2.0);
}

void MyCanvas::OnUpdate()
{
    // On efface l'écran
    clear(sf::Color(0, 128, 0));

    // Une petite rotation du sprite
    mySprite.rotate(0.05 * 100.f);

    // Et on l'affiche
    draw(mySprite);
}


 
« Modifié: Janvier 03, 2014, 12:52:04 am par djentx »

djentx

  • Newbie
  • *
  • Messages: 5
    • Voir le profil
Re : Compilation avec QtCreator :-1: undefined reference to
« Réponse #1 le: Janvier 02, 2014, 07:17:29 pm »
Il est bon de signaler que j'arrive a faire un programme Qt5.0.2 / SFML2.1 avec QtCreator comprenant une fenêtre QMainWindow et une sf::RenderWindow distincte sans problème.
« Modifié: Janvier 03, 2014, 12:52:27 am par djentx »

 

anything