SFML and other new libs in VS 2010

Hi, first post here.

I know some of you might have seen this topic before. I have searched through the archives but I have never found anything that corresponds to my problem.

I have been trying to get SFML to work on VS 2010. Somedays it will work, but most of the time it wont. The problem is the linker. Since I'm not a pro by any means, I started programming in October and I'm currently on chapter 14 in C++ Primer Plus, I don't know what the problem is.

I have built he solution according to this video http://www.youtube.com/watch?v=-uHGZGgMETg at 0:50. Then I have put the libs and dlls in VS' lib folder and the includes in the include folder. VS does recognize the headers, so that's no problem.

However at 3:16 he does something with the linker/input and this is where I think the problem occurs. Somedays typing sfml-graphics-s-d.lib works, and sometimes it wont. But this doesn't happen with system or window, only with graphics (I haven't tried the others).

with this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <SFML\Graphics.hpp>

int main()
{
	sf::RenderWindow App(sf::VideoMode(800, 600, 32), "TEST");

	sf::Event Event;

	while(App.IsOpened())
	{
		while(App.GetEvent(Event))
		{
			if(Event.Type == sf::Event::Closed)
				App.Close();
		}
		App.Clear();

		App.Display();
	}

	return EXIT_SUCCESS;
}


I get errors like these:
1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (??1RenderWindow@sf@@UAE@XZ) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Display(void)" (?Display@Window@sf@@QAEXXZ) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (?Clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@QAE@EEE
(and about 20 more like these)

I have also tried typing in sfml-graphics.dll in the linker/input, but that wont work either

I'd be terribly happy if someone knows what the deal is
I've only just started with SFML too, so someone else can probably explain things better.

However, the file I have been using for the system core is called sfml-system.lib. Therefore, for graphics maybe you should link the library sfml-graphics.lib. There are also (as you know) SFML libraries with various letters at the end. I think -d might mean debug, but I have no idea about -s...

Also, you mentioned linking the dll file. While I am no expert and I may be wrong, I am pretty sure that you won't get anywhere linking dynamic libraries as if they were static. I think for DLLs you have to copy and paste them into your project's Debug directory, or you'll get a runtime error.

As I've said, I may be wrong, but I hope this helps anyway!
Well, that's another problem, I don't have sfml-graphics.lib. I only have the dll version
Oh. Another thought. There seems to be another library file called sfml-window.lib. Perhaps you should add this to the link library list as well.

It looks like the -s in the library path stands for static. Were you intending to use the static rather than dynamic library?
Really? Did you say you're using visual studio? On this page http://sfml-dev.org/download.php, there is a link for a Microsoft Visual C++ 2008 full SDK download (the third on the list). This is the one I downloaded and I definitely have for each library:
- a DLL
- 4 lib files with various endings to them
The problem is that I'm using VS 2010, not 2008. The express verison.
Because of that I have to rebuild and do things that I don't understand.
I think that I'm going to try 2008 just to see if it makes a difference.
I am using VS 2010 (although it is the pro version) too and I just used the VC2008 download. The libraries that came straight with that seemed to work - I know I didn't have to build it myself because I'm pretty sure I would have failed :P

By the way, I don't know you're situation, but if you are a student, you can get MS Visual Studio Professional for free here http://www.microsoft.com/uk/wave/software-dreamspark.aspx. The license is quite strict though (no commercial use etc).
So does that mean I can't program games in it?

And I have tried the regular 2008 libs. The only thing I didn't try then was to write the libs names int the linker/input.

Does anybody know why you have to do that?
I'm not sure. In the license it says it's for STEM-D (Science, Technology, Engineering, Mathematics and Design) research only. So maybe not. Definitely not to program games and then distribute them. Maybe I need not have brought Dreamspark up. As I said, it is strictly licensed. SFML should work with Express too, I'd have thought, so ultimately for freedom of usage of your code, I'd stick with the express edition (sorry to backtrack on that one...)

I'm sorry I don't quite understand. Have you written the library names into the linker input? If not, how have you linked the libraries to your project?

The reason you have to link libraries is so that the functions etc declared in the SFML header files you use actually have definitions. I'm not sure if this is what you are asking though. If not, let me know.
Yeah, I'm not sure either. I'm quite new to programming so I don't know half of the shit I'm doing when I'm manipulating the compiler.

I am however going to try it with the regular files and see if it works.
Yeah that's what I have done and it works (at least in MSVC 2010 Pro). Let me know how you get on. If it doesn't work, maybe we can think of something else. The whole reason I swapped to SFML is that I had this problem with another library and couldn't fix it, so I know how much of a pain it can be!
ok, If I put sfml-graphics.lib in Linker/Input it will compile.

However, the moment it tries to execute it just says "This program won't start because sfml-graphics.dll can't be found".

I included that right in there with all the other library files!!
What is VS doing?!?!
I had this problem too. Basically, sfml-graphics.lib is the wrapper for the dynamic library sfml-graphics.dll (I think...).

To fix this problem you have to put the required dll files in the same directory as your executable file (e.g. ...\Solution Name\Debug\). I imagine this is because DLL files are loaded by the SFML runtime, not the Visual Studio compiler or linker. Therefore you have to put them where your program can find them!

Alternately, you just replace the linker reference to sfml-graphics.lib by sfml-graphics-s.lib. This version of the library contains all the code itself so you don't need the DLL. However, I think it's best to use the first option.

One other important point. Do you know about the build configuration things in Visual Studio (i.e. Debug and Release). I have just read that for the debug configuration you should not link
sfml-graphics.lib, but sfml-graphics-d.lib (this is the debug version). For the release configuration, use sfml-graphics.lib. This step is apparently important, since without it debugging won't always work.

Let me know if any of this is unclear and I can re-explain :)
ok, I tried putting it in the debug folder, it still couldn't find it.

When I put it in the solution folder I get error (0xc0150002) saying that the program couldn't be initated properly.

FML

EDIT: and sfml-graphics-s-d.lib wont wok either =(
Last edited on
I suggest you link sfml-graphics-d.lib (note, no -s) rather than sfml-graphics.lib. This is the debug library so perhaps it will give a more friendly error message.

EDIT: Remember to compiler and run your project under debug configuration rather than release configuration. Also make sure you run it with the debugger (this should be possible just by pressing F5 in Visual Studio.)
Last edited on
I tried with with -d, but the problem isn't compile-time, it's when the program is trying to execute.
It won't initiate.
I'm out of ideas sorry. However, I found this forum on google http://www.sfml-dev.org/forum/viewtopic.php?p=18508&sid=18981136419d8573a5bc6870f3610616. Sadly it says you need to recompile SFML yourself, but there's a link to a video when someone takes you through the process. Maybe it's worth a look.
Well, after rebuilding I have finally gotten it to work.

Let's see how it'll work tomorrow (it proably wont)

Atleast I'm getting some success

EDIT: Oh, I almost forgot:
Thanks a bunch, I really appreciate it :)
Last edited on
That's OK - I'm not sure how much I helped though.

EDIT: As I said before, I don't think I explained the Debug/Release configuration thing very well, but the guy in that video went through it all, so it's there if you haven't already set up the two configurations (basically, libraries with -d at the end are for debug config, those without are for release).

PS: I randomly started getting the same runtime error yesterday so I guess it's a rebuild for me too.

EDIT: I've done that release and it's working now! In future I'll probably be rebuilding these things for myself from the start to save me the intermediate effort!
Last edited on
Topic archived. No new replies allowed.