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

Author Topic: Problem with compling an example code  (Read 1686 times)

0 Members and 1 Guest are viewing this topic.

lotnik9o

  • Newbie
  • *
  • Posts: 6
    • View Profile
Problem with compling an example code
« on: February 20, 2012, 08:18:56 pm »
I have to make the SFML headers and library files available to Visual C++ 2008 and after bulid:

Code: [Select]
#include <SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}


It gives me the following errors:

Code: [Select]
1>------ Build started: Project: sf_test, Configuration: Release Win32 ------
1>Linking...
1>testx.obj : error LNK2001: unresolved external symbol "void __cdecl sf::Sleep(float)" (?Sleep@sf@@YAXM@Z)
1>testx.obj : error LNK2001: unresolved external symbol "public: float __thiscall sf::Clock::GetElapsedTime(void)const " (?GetElapsedTime@Clock@sf@@QBEMXZ)
1>testx.obj : error LNK2001: unresolved external symbol "public: __thiscall sf::Clock::Clock(void)" (??0Clock@sf@@QAE@XZ)
1>C:\Users\Szymon\Documents\Visual Studio 2008\Projects\sf_test\Release\sf_test.exe : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://c:\Users\Szymon\Documents\Visual Studio 2008\Projects\sf_test\sf_test\Release\BuildLog.htm"
1>sf_test - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Can someone help me how to solve this problem?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with compling an example code
« Reply #1 on: February 20, 2012, 08:25:14 pm »
You must link to sfml-system. Please read the tutorial before posting ;)
Laurent Gomila - SFML developer

silentdth

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problem with compling an example code
« Reply #2 on: March 05, 2012, 12:14:29 pm »
Just a warning that this sample code doesn't work with SFML2.
I believe it's because Clock.GetElapsedTime() now returns an sf::Time object instead, not a float.

Some other sample code to try for SFML2 users:

Code: [Select]
#include <SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock clock;
    //while (Clock.GetElapsedTime() < 5.f)
    //{
        //std::cout << Clock.GetElapsedTime() << std::endl;
    //    sf::Sleep(0.5f);
    //}
   
    sf::Time time1 = clock.GetElapsedTime();
    std::cout << time1.AsSeconds() << std::endl;
    return 0;
}