Bonjour,
J'ai voulu créer une classe qui gère une RenderWindow (en tant que membre) et ainsi créer un semblant de GUI, mais quand j'essaie d'initialiser la RenderWindow dans la liste d'initialisation, j'ai des erreurs du genre :
undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
Etc.
J'utilise Code::Blocks 13.12 avec GCC 4.7.1 MinGW.
| | === Build: Debug in Rabbits like coins (compiler: GNU GCC Compiler) === |
-c | | No such file or directory [enabled by default] |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindowC2EbiiRKN2sf6StringE': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 7 | undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 7 | undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 9 | undefined reference to `_imp___ZN2sf6Window10setVisibleEb' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 7 | undefined reference to `_imp___ZN2sf12RenderWindowD1Ev' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindowC2EbRKN2sf9VideoModeERKSs': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 14 | undefined reference to `_imp___ZN2sf6StringC1ERKSsRKSt6locale' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 14 | undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 16 | undefined reference to `_imp___ZN2sf6Window10setVisibleEb' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 14 | undefined reference to `_imp___ZN2sf12RenderWindowD1Ev' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindowD2Ev': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 24 | undefined reference to `glan::ButtonsList::clear(bool)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 19 | undefined reference to `_imp___ZN2sf12RenderWindowD1Ev' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 19 | undefined reference to `_imp___ZN2sf12RenderWindowD1Ev' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindow4showEv': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 31 | undefined reference to `_imp___ZN2sf6Window10setVisibleEb' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 40 | undefined reference to `_imp___ZN2sf6Window5closeEv' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 36 | undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 33 | undefined reference to `_imp___ZNK2sf6Window6isOpenEv' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindow5closeEv': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 47 | undefined reference to `_imp___ZN2sf6Window5closeEv' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindow10updateDispEv': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 53 | undefined reference to `_imp___ZN2sf5ColorC1Ehhhh' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 53 | undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 56 | undefined reference to `_imp___ZN2sf6Window7displayEv' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZN4glan9absWindow13updateButtonsEv': |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 61 | undefined reference to `glan::ButtonsList::ButtonsList(bool)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 64 | undefined reference to `glan::ButtonsList::operator=(glan::ButtonsList const&)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 74 | undefined reference to `glan::ButtonsList::operator[](unsigned int)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 76 | undefined reference to `glan::ButtonsList::operator[](unsigned int)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 76 | undefined reference to `glan::Button::isEnabled() const' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 77 | undefined reference to `glan::ButtonsList::operator[](unsigned int)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 79 | undefined reference to `glan::ButtonsList::operator[](unsigned int)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 79 | undefined reference to `glan::Button::isHidden() const' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 80 | undefined reference to `glan::ButtonsList::operator[](unsigned int)' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 80 | undefined reference to `_imp___ZN2sf12RenderStates7DefaultE' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 80 | undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 72 | undefined reference to `glan::ButtonsList::size()' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 83 | undefined reference to `glan::ButtonsList::~ButtonsList()' |
C:\Users\Jules\Desktop\Documents\C++\Projets SFML\Rabbits like coins\absWindow.cpp | 83 | undefined reference to `glan::ButtonsList::~ButtonsList()' |
C:\Users\Jules\AppData\Local\Temp\ccixam45.o | | In function `ZSt8_DestroyIN4glan11ButtonsListEEvPT_': |
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_construct.h | 95 | undefined reference to `glan::ButtonsList::~ButtonsList()' |
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7) | | undefined reference to `WinMain@16' |
| | === Build failed: 36 error(s), 0 warning(s) (0 minute(s), 0 second(s)) === |
Et le code :
absWindow.h :
#ifndef ABSWINDOW_H
#define ABSWINDOW_H
#include <SFML/Graphics.hpp>
#include "ButtonsList.h"
namespace glan
{
// A class to handle a window and its buttons and event loop.
// The constructor does NOT show the window. Add window.setVisible(true) in your show() function.
class absWindow : sf::NonCopyable
{
friend class Button;
public:
absWindow(bool destrDeleteButtons = true, \
int x = 600, int y = 800, sf::String const& title = "Window");
// Arguments :
//
// x : the height of the window.
//
// y : the width of the window.
//
// title : the title shown in the title bar of the window.
//
// destrDeleteButtons : sets deleteButtons, which defines if the destructor deletes the buttons of the 'buttons' member.
absWindow(bool destrDeleteButtons = true, \
sf::VideoMode const& videoMode = sf::VideoMode(800,600), std::string const& title = "Window");
// Arguments :
//
// videoMode : the video mode of the window.
//
// title : the title shown in the title bar of the window.
//
// destrDeleteButtons : sets deleteButtons, which defines if the destructor deletes the buttons of the 'buttons' member.
virtual ~absWindow() = 0;
// Destructor. If 'resetRect' member is true, deletes all glan::Button in 'buttons' member.
virtual void show();
// Shows the window.
void useBtnsVect(int i = -1);
// Sets 'btnsVectShown' member at 'i'.
void close();
// Closes the window and destroys this.
virtual void updateDisp();
// Should call updateButtons().
protected:
void updateButtons();
// Drawn all buttons contained in 'buttons' member at(btnsVectShown), excepts these which are hidden. If buttons[btnsVectShown] is out of range, no button is
bool deleteButtons;
int btnsVectShown;
std::vector<ButtonsList> buttonsLists;
sf::RenderWindow window;
sf::Event event;
};
} // namespace glan
#endif // ABSWINDOW_H
absWindow.cpp
#include "absWindow.h"
using namespace glan;
absWindow::absWindow(bool destrDeleteButtons, int x, int y, sf::String const& title) : \
deleteButtons(destrDeleteButtons), btnsVectShown(-1), buttonsLists(), \
window(sf::VideoMode(x, y), title, sf::Style::Titlebar | sf::Style::Close)
{
window.setVisible(false);
}
absWindow::absWindow(bool destrDeleteButtons, sf::VideoMode const& videoMode, std::string const& title) :
deleteButtons(destrDeleteButtons), btnsVectShown(-1), buttonsLists(), \
window(videoMode, title, sf::Style::Titlebar | sf::Style::Close), event()
{
window.setVisible(false);
}
absWindow::~absWindow()
{
if(deleteButtons)
{
for(int i(0) ; i < (int)buttonsLists.size() ; i++)
buttonsLists[i].clear();
}
}
void absWindow::show()
{
window.setVisible(false);
while(window.isOpen())
{
updateDisp();
while(window.pollEvent(event))
{
updateDisp();
if(event.type == sf::Event::Closed)
window.close();
}
}
}
void absWindow::close()
{
window.close();
delete this;
}
void absWindow::updateDisp()
{
window.clear();
updateButtons();
// Other drawings...
window.display();
}
void absWindow::updateButtons()
{
ButtonsList temp;
try
{
temp=buttonsLists.at(btnsVectShown);
}
catch (std::out_of_range const& expt)
{
std::cerr<<expt.what()<<std::endl<<"absWindow.cpp::updateButtons()"<<std::endl;
return;
}
for(int i(0) ; i < (int)temp.size() ; i++)
{
if(temp[i] != nullptr)
{
if(temp[i]->isEnabled())
temp[i]->checkClicked(event, window);
if(!temp[i]->isHidden())
window.draw(*temp[i]);
}
}
}