SFML community forums
Help => General => Topic started by: aBallofWin on January 08, 2012, 06:20:09 pm
-
Hey, I'm trying to compile the following code:
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
#include "AniSprite.h"
int main()
{
sf::RenderWindow App(sf::VideoMode(640, 420,32), "Test");
sf::Image Image;
if (!Image.LoadFromFile("untitled1.bmp"))
return 1;
Image.CreateMaskFromColor(sf::Color::Black);
AniSprite Sprite(Image,93,96);
Sprite.SetLoopSpeed(0.007); //60 fps
while(App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
Sprite.Play();
else if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::A))
Sprite.Stop();
}
App.Clear();
Sprite.Update();
App.Draw(Sprite);
App.Display();
}
}
and I get
/home/aballofwin/Downloads/frame_anim_animated/sample/main(1).o||In function `main':|
main(1).cpp|| undefined reference to `AniSprite::AniSprite(sf::Image const&, int, int)'|
main(1).cpp|| undefined reference to `AniSprite::SetLoopSpeed(float)'|
main(1).cpp|| undefined reference to `AniSprite::Play()'|
main(1).cpp|| undefined reference to `AniSprite::Stop()'|
main(1).cpp|| undefined reference to `AniSprite::Update()'|
main(1).cpp|| undefined reference to `AniSprite::~AniSprite()'|
main(1).cpp|| undefined reference to `AniSprite::~AniSprite()'|
||=== Build finished: 7 errors, 0 warnings ===|
and I was wondering if there's a linker option I'm missing, or something else?
-
You are probably missing a lib file.
-
The following files that i have in the directory of the main file are:
anim.hpp
animated.cpp
animated.hpp
AniSprite.cpp
AniSprite.h
frame.cpp
frame.hpp
main(1).cpp
pausableclock.hpp
sfml-audio.dll
sfml-graphics.dll
sfml-system.dll
sfml-window.dll
untitled1.bmp
anything you notice is missing from that?
-
Have you included AniSprite.cpp in your project?
Putting it in the same folder isn't enough.
-
Cheers :) I put #include "AniSprite.cpp" at the top
-
I put #include "AniSprite.cpp" at the top
A cpp file is a source file and shouldn't be included like a header file.
If it works for you then its good, but it is not the correct way to do it.
You should add it just like the main.cpp file or any other source file.