SFML Link Error

Hello. I'm just starting to learn the SFML library for use in C++ in VSE 12.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Main.cpp */
#include "Header.h"

int main(void){
	sf::Window window;
	window.create(sf::VideoMode(1280, 720), "My window");

	sf::Font font;
	if (!font.loadFromFile("arial.ttf")){}

	sf::Text text;

	text.setFont(font);
	text.setString("Hello world");
	text.setCharacterSize(24);
	text.setColor(sf::Color::Red);
	text.setStyle(sf::Text::Bold | sf::Text::Underlined);

	while(window.isOpen()){
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
			window.close();
		}
	}

	return 0;
}


1
2
3
4
5
6
7
8
/*  Header.h */
#pragma once

#include <SFML\System.hpp>
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
#include <SFML\Graphics\Color.hpp>


1>------ Build started: Project: RPG-C-VS, Configuration: Debug Win32 ------
1>Main.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Red" (?Red@Color@sf@@2V12@B)
1>Z:\Storage\Code\Projects\RPG\RPG-C-VS\Debug\RPG-C-VS.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

As far as I can tell I am getting an error related to the use of the Color class. I figured the inclusion of Color.hpp would fix this but it has not.

I thank you in advance for all and any help. :)
Last edited on
Firstly, there's no need to include Color.hpp, nor for that matter System or Window as Graphics includes them all. What did you link to? I would advise setting up a new project with SFML as this is often easier than hunting down small mistakes in linking. Also tags use [ and ] not < and >,
Thanks for the advice.

Debug Dependencies:
1
2
3
4
5
6
7
8
sfml-system-d.lib
sfml-graphics-d.lib
sfml-window-d.lib
opengl32.lib
freetype.lib
jpeg.lib
winmm.lib
gdi32.lib


Release Dependencies:
1
2
3
4
5
6
7
8
sfml-system-s.lib
sfml-graphics-s.lib
sfml-window-s.lib
opengl32.lib
freetype.lib
jpeg.lib
winmm.lib
gdi32.lib


I hope that is what you were asking for. The code I originally posted is the only code currently in my project. I wrote it up for testing purposes to make sure everything was working properly.
Linking order usually matters for this sort of thing. Try linking graphics then window then system.
After changing the link order the original error remains.

Perhaps I don't have the correct .dll files where they need to be. I can not say for myself if that would be the cause, however.
You need to put -s-d for the debug configuration. Also, did you define SFML_STATIC?
Last edited on
Changing the debug configuration as said causes more errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
1> Build started: Project: RPG-C-VS, Configuration: Debug Win32
1>  Main.cpp
1>sfml-graphics-s-d.lib(Transformable.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Font.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Text.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Color.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Transform.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Image.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Texture.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(GLCheck.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(VertexArray.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(RenderTarget.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(GLExtensions.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(TextureSaver.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(GLLoader.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(View.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Shader.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(VideoMode.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(Window.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(InputImpl.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(VideoModeImpl.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(GlContext.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(WindowImpl.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(WglContext.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(JoystickManager.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(SensorManager.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(WindowImplWin32.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(WglExtensions.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(Joystick.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-system-s-d.lib(String.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-system-s-d.lib(Err.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-system-s-d.lib(ThreadLocal.cpp.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1700' in Main.obj
1>sfml-graphics-s-d.lib(Shader.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::operator bool(void)const " (__imp_??Bios_base@std@@QBE_NXZ) referenced in function "bool __cdecl `anonymous namespace'::getFileContents(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<char,class std::allocator<char> > &)" (?getFileContents@?A0xa379d511@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@DV?$allocator@D@std@@@3@@Z)
1>sfml-system-s-d.lib(Time.cpp.obj) : error LNK2019: unresolved external symbol __ftol3 referenced in function "class sf::Time __cdecl sf::seconds(float)" (?seconds@sf@@YA?AVTime@1@M@Z)
1>sfml-system-s-d.lib(Time.cpp.obj) : error LNK2019: unresolved external symbol __ltod3 referenced in function "public: float __thiscall sf::Time::asSeconds(void)const " (?asSeconds@Time@sf@@QBEMXZ)
1>Z:\Storage\Code\Projects\RPG\RPG-C-VS\Debug\RPG-C-VS.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I defined SFML_STATIC by method of the 'Preprocessor' settings under 'C/C++.'
Okay sorry if I can't help more, I've told you all the things I can think of (did you try just making a new project?). I'd advise going over to the sfml website and posting those errors. The people who actually made it are there so they'll be the best at helping you.
No problem. I appreciate the help you have provided up to this point. I will be sure to come back to this thread with an update on this problems resolution.
I was pointed in the correct direction on the SFML forums. Apparently I needed to link dynamically in my situation, which involved no suffix on the release builds, and only '-d' on the debug builds. In addition I had to get rid of SFML_STATIC.

Thanks for all the help! :)
Topic archived. No new replies allowed.