SFML Tutorial not up to date? - c++

I've followed this tutorial to the letter in order to set up SFML 2.0 with Visual Studio Express 2012: http://www.sfml-dev.org/tutorials/2.0/start-vc.php
For some reason though I get 16 Unresolved LNK Errors. I am not sure what I am doing wrong. I follow the tutorial to the letter. At the point about using Static or Dynamic libraries I didn't add for example sfml-audio-s.lib I just added sfml-audio.lib as first advised.
This is the code the tutorial use as well:
#include <SFML\Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(200,200), "SFML Works!");
CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while(window.isOpen())
{
Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Is this tutorial just outdated or is it just me doing something horribly wrong?

LNK2019 is a Linker Error which can mean two things:
you didn't install the libraries correctly and/or didn't tell visual studio about these files
you are using code which uses another version of that library
You seem to use SFML2.0 since pollEvent() doesn't exist in v1.6.
Make sure you are using the right version and did configure Visual Studio correctly.

Related

SFML Unresolved external symbol (LINKER FAIL)

#include "SFML/Graphics.hpp"
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event e;
while (window.pollEvent(e))
{
if (e.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
I am not sure, why my program doesn't work. I tried to write libraries in input in Linker settings, but still not working. Also I defined SFML_STATIC for preprocessor heading, however I'm not sure do I need this or not.
I want to my code working. Everything was explained above.
perhaps run your program in both debug and release mode. then copy the bin/dll files over to those folders. also remove SFML_STATIC and you should be good to go, if youre using debug mode be sure to add -d to the linker input! hope this helps.
and also be sure youre using x86 version. you really shouldnt touch x64 unless you have some very specific apps you have to make.

While using SFML I am getting a memory or out of bounds exception, what is the issue?

I am learning how to link SFML so I can use the window tools. My ultimate goal is to write some sort of Chess or Asteroid game just to practice getting better at programming. I used the SFML tutorial to get all of my linking straightened out, and I am doing it dynamically with the .dll files. Everything in this code compiles on Visual Studio 2017, but when the console comes up the error I get is , "The application was unable to start correctly (0xc000007b)."
I am assuming this is some sort of memory error? It took me a while to learn the linking and now I am stuck. Thanks for any help!
PS. This is just suppose to be a simple display a window with a green circle inside of it.
#include "pch.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <time.h>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(200,200), "My First Window");
CircleShape shape(100.f);
shape.setFillColor(Color::Green);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
{
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
}
return EXIT_SUCCESS;
}
The answer is already mentioned in the comments, but I will put an actual answer here so it's more visible.
The error code 0xc000007b means that the required .dll files are not in located in PATH or the local directory. To fix this issue, either place your required .dlls in a directory in the system PATH, or in the executable directory.
Also, you need to make sure that you do not mix 32 bit and 64 bit libraries, they are incompatible with each other.
Thank you drescherjm.

SFML tutorial not even working

I installed SFML on codeblocks with their tutorial, following it step by step. Everything has been checked and done correctly, yet their sample program is not even building correctly. It seems that codeblocks cannot even find the basic functions of SFML.
What did I miss?
Error log :
( http://i.imgur.com/eaGz9HK.jpg )
My code :
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
It's very strange to give a library location -L and then explicitly link to the exact library. So, instead of giving the full path to the library, just give it's name. So, instead of ..\..\..\..\..\LOGICIELS\CodeBlocks\SFML\libs\libsfml-graphics-s-d.a just say sfml-graphics-s-d. Do this for all libraries
When you see -L..\..\..\..\..\..\LOGICIELS\CodeBlocks\SFML\lib you are telling the compiler (linker) where to find the libraries. The convention with libraries is that they are prefaced with lib and followed by .a. So, change you library linkage to just the name of your library, sans lib and .a
so, after obj\Debug\main.o, it should be sfml-grphics-s-d sfml-window-a-d sfml-system-a-d sfml-main-d

SFML 2.0 Crashing (Error on window-d-2

Using Code::Blocks, W7, Ati Card
I have this silly problem, I tried to compile a sample program from SFML website - http://www.sfml-dev.org/tutorials/2.0/start-cb.php
Everything set correctly, I think. When I start (Build and run) It throws out a crash, when looking into crash details it points out window-2-d.
All the .dll files are in the project directory, obviously a dynamic build.
RC from the website, for version 2.0 (I couldn't use 1.6 anyway because of ATI bug)
Tried to use this code to run it
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Help?
If you're using the latest Code::Blocks version, which includes GCC 4.7.1, then you have to recompile SFML on your own (or use my Nightly Builds), because the ones provided are only for GCC versions < 4.7.x.
I couldn't use 1.6 anyway because of ATI bug
SFML 2 is better anyways, so don't worry.

Using SFML with Visual Studio 2010

Right now I'm trying to get SFML to work with my Visual Studio 2010, so I can start learning how to make windows applications and games using the libraries within SFML. I'm following the tutorial here to open a new window, but my program seems to break instantly. I really don't know why :S. It seems to build and compile, but then breaks:
Edit: It breaks at this line: App.Create(sf::VideoMode(800, 600, 32), "SFML Window");
#include <SFML/Window.hpp>
int main ()
{
sf::Window App;
App.Create(sf::VideoMode(800, 600, 32), "SFML Window");
bool Running = true;
while (Running)
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Running = false;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
Running = false;
}
App.Display();
}
return EXIT_SUCCESS;
}
Also, I should note:
On the SFML website, the tutorials for setting it up with Visual Studio seem to be for VS 2008 (Setting up SFML with VS). I managed to get a set of instructions for VS2010 and set it up. I used a short program to test if the SFML libraries were working:
#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;
}
^ This program worked fine.
The SFML libraries are compiled for Visual Studio 2008. If you use it with VS2010, it will 'kind of' work. You'll get messages about a corrupted stack, and possibly other hard crashes when you call certain functions (like App.Clear()).
You need to either recompile the source code for the libraries yourself, or find a version where somebody else has done that. I don't believe there's an 'official' source, but if you search the forums at the SFML site, you'll find some links to libs compiled for 2010.
Late answer, I know... but this question is still coming all the time.
I'm pretty sure the error you are getting here is because you used Window instead of RenderWindow.