Help with SFML linker error

Pages: 12
closed account (3qX21hU5)
So just starting getting familiar with SFML and I'm having some trouble understanding the tutorial on their website to setup everything for Visual Studios.

Im currently testing out the VS Ultimate 2012 on this computer. I have moved all the SFML include and lib file to the correct folders in my VS folder. The problem I'm having in this part of the tutorial.

Open your project's options, then go to the linker/Input item. In the Additional dependencies row, add the SFML libraries you are using.


So yesterday I followed the tutorial to setup the linker and got the following code running by adding sfml-system.lib (I think or it was sfml-system-s.lib).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <SFML\System.hpp>
#include <iostream>

using std::cout;
using std::endl;

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

	return 0;
}


But now for the life of me I can't get it to run again so I was wondering if anyone could give me some instructions or maybe explain more how to setup the linking of the SFML libraries. Thanks in advance for the help

Edit: Here is the errors I get while debugging if they can help.

1>------ Build started: Project: SMFL Learning, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Users\Brandon\Documents\Visual Studio 2012\Projects\SMFL Learning\Debug\SMFL Learning.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Try changing the subsystem to console in Project->properties->linker->system.
closed account (3qX21hU5)
Thanks naraku now I have got that fixed by changing it to a console program and using the sfml-system-s.lib and it compiles and runs perfect.

Now here is my main problem. Im now starting to get into creating windows with SFML. I create a new Windows Application project (since I dont want the consule to show up) and add sfml-window-s.lib and sfml-main.lib in the linker.

I try to run this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <SFML\Window.hpp>

int main()
{
	sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window Tutorial");

	bool Running = true;
	while (Running)
	{
		App.Display();
	}

	return EXIT_SUCCESS;
}


And again I get linker errors. I have tried switching to a console app like you suggest above but still getting linker errors. Any suggestions? I just dont think im getting my head around how linking works and which .lib file I should use (sfml-window.lib, sfml-window-s.lib, sfml-window-s-d.lib, sfml-window-d.lib). Thanks in advance for the help

To get rid of the console window you will need to use the winapi to create the window and embed the sfml RenderWindow in a static control. You can also use Qt, wxWidgets, etc for window creation instead of winapi directly.

Edit:
sfml-window.lib --dynamic(DLL) release build,
sfml-window-s.lib --static release,
sfml-window-s-d.lib --static debug,
sfml-window-d.lib --dynamic debug

Match to your system settings. I have a VS2010 project wizard that sets up linker settings, but I haven't updated it to VS2012 yet. http://code.google.com/p/sfml-project-wizard/
Last edited on
Post the new linker errors for us.
I know it's a pain. It took me literally ages to finally wrap my head around it. I still remember spending outrageous amounts of time trying to get SFML to work for the first time.

SFML libs with the postfix '-s' are statically linked, ones that aren't are dynamically linked. the '-d' postfix is a debug library (which I've personally never used.)

Statically linked libraries are in all effects copied into your .exe file when you compile.
Dynamically linked libraries aren't. So, for example, you would need to have "sfml-window.dll" in the same folder as the executable in order for it to run.

It's pretty frustrating to get a hold of, but once you do you feel really good about yourself.

@naraku9333
Could you change the subsystem back to Windows, then just declare WinMain instead of main? That way no console window is created. Just a hunch.
closed account (3qX21hU5)
Thanks Disch that simplifies things a lot and now can get started on learning SFML and deal with linkers later when I have more time for it.

And its my understanding that WinMain isn't portable thats why its better to use main.
Disch, the master of everything, and the source of envy.

Fair enough, then. I know little about the Windows API.
There are also methods in the WinAPI that allow you to hide a console window. I can't remember remotely what they're called; the last time I used them was 5 years ago as a script kiddie while attempting to make a homebrew keylogger for my machine.
closed account (3qX21hU5)
Actually jsut tested the header you gave me disch. I just copied the code to a header file and placed the head in my SFML include folder in the VS folder. And im still getting linker errors when I run it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <SFML\sfml.h>

int main()
{
	sf::Window App(sf::VideoMode(800, 600, 32), "SFML WINDOW TUT");

	bool running = true;
	while (running)
	{
		App.Display();
	}

	return EXIT_SUCCESS;
}


To long to post all the errors but here are some.

1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::ios_base::width(int)" (__imp_?width@ios_base@std@@QAEHH@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::ios_base::width(int)" (__imp_?width@ios_base@std@@QAEHH@Z)
1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (__imp_?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (__imp_?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z)
1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl std::char_traits<char>::eof(void)" (__imp_?eof@?$char_traits@D@std@@SAHXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __cdecl std::char_traits<char>::eof(void)" (__imp_?eof@?$char_traits@D@std@@SAHXZ)
1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::ios_base::width(void)const " (__imp_?width@ios_base@std@@QBEHXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::ios_base::width(void)const " (__imp_?width@ios_base@std@@QBEHXZ)
1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (__imp_?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Sentry_base::_Sentry_base(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0_Sentry_base@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (__imp_?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ)
1>sfml-window-s-d.lib(Window.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (__imp_?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Sentry_base::~_Sentry_base(void)" (??1_Sentry_base@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (__imp_?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ)
1>c:\users\brandon\documents\visual studio 2012\Projects\Win32Project2\Debug\SFML Windows.exe : fatal error LNK1120: 12 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
closed account (3qX21hU5)
I'm assuming that it works on your machine so maybe I'm messing up when I'm copying the SFML include files and libs to my VS folder?
Looks like issues with linking to the standard lib runtime.

Go in your solution properties, in "Configuration Properties" -> "C/C++" -> "Code Generation", switch the runtime library from "Multithreaded Debug" to "Multithreaded Debug DLL" (or vice versa), see if that helps.
closed account (3qX21hU5)
Changed it from Multithreaded Debug DLL to Just Multithreaded Debug, and still getting errors. I'm going to jump on my main computer instead of my laptop and try a clean install of the 1.6 version of SFML, and retry setting it up. Ill give a update in a sec here
Try calling convention under c/c++ -> advanced, change to cdecl
closed account (3qX21hU5)
@naraku Already is set to cdecl.

Ok went to my main computer which is running the full version of VS 2010 Professional. And I'm just going to go over every step to see if I'm installing wrong.

Downloaded SFML 1.6, and extracted the files and copied the SFML include file to my VS folder
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
and the lib files to the VS lib folder.

Next I created the header file disch provided and put it in the SFML include folder in my VS directory.

Ran the same code as before and still getting the same error messages. So I must be doing something wrong :(


closed account (3qX21hU5)
Think I found the problem.

You must download the package that matches your version of Visual C++. Indeed, a library compiled with Visual C++ 2008 won't be compatible with Visual C++ 2005 or 2011 for example. If there's no SFML package compiled for your version of Visual C++, you will have to recompile SFML.


So looks like I need to recompile SFML time to open Cmake again
Zereo is right. I just installed SFML on my system again (i recently reinstalled windows because my stuff was getting cluttered.) I use Visual Studio 2010 pro, and i was getting the same errors as you to begin with. I forgot how i got it to work last time until Zereo just mentioned that.

I assume you downloaded the SFML build for Visual Studio 2008. Go to: <LibraryLocation>/build/vc2008.
Open up SFML.sln, and let visual studio convert the project into the 2010 format. Once that wizard is finished, you should see all the SFML libraries are project in the solution explorer.
Click Build->Batch Build. Check all of the SFML libraries to build -- you can ignore building all the examples, but you can just as easily build those too.

However, I get errors when building all the static debug libraries (for reasons beyond me.) Until someone with higher intelligence figures out what
Error	46	error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in AudioDevice.obj	C:\SFML-1.6\build\vc2008\sfml-system-s-d.lib(Sleep.obj)

means, you can just modify Disch's SFML header to always use static release libraries, which appear to be working for me after i built the library with Visual Studio.
As long as you're rebuilding SFML, you probably should be using 2.0, not 1.6.

Until someone with higher intelligence figures out what [errormsg] means,


That error means the debug build is linking to release libs. If you're getting that error when building SFML, then it might be a problem with SFML's linker settings (which is worth reporting on the SFML boards -- if this is sfml 2.0), or it might mean that you don't have all the necessary dependencies installed on your machine (although this seems unlikely because I thought the SFML package included all its dependencies... but I might be wrong there).
You're right. I went and grabbed the latest release of SFML 2.0.
Follow this tutorial: http://www.youtube.com/watch?feature=player_embedded&v=PtSDrLpV74M#!
He did a really good job of explaining how to build it.

Everything works on my end after that.
closed account (3qX21hU5)
So decided to give up on trying to install SFML on VS. I can get it to work perfectly on Codeblocks but for some reason VS wants to be a pain in the ass (Imagine that ;p). I just find it funny that SFML is aimed at beginner level programmers that want to get into API's. Yet it is extremely hard to setup and use.

The main problem for me is compiling a new version of SFML for VS 2012, so if anyone happens to have a compiled version of SFML 2.0 that is compatible with VS 2012 I would be grateful if you could pass me the updated headers and libraries.
Yeah, it's definitely one of SFML's bigger problems, IMO. For more advanced guys it's not really a big deal, but for beginners looking to just pick up and use something, the setup leaves a lot to be desired.
Pages: 12