Errors when trying to debug the code (SFML)

Hello!

I'm currently just trying C++ with SFML, and yeah

So I've installe SFML 2.0 for Visual C++ 2010 Express 64 bit, and I get an error while trying to run the debug of my code.

1
2
3
4
5
6
7
8
9
10
//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
	sf::RenderWindow window(sf::VideoMode(1280, 720),"SFML Game1");

	return 0;
}


And this is the result I'm getting when trying to run it


1>------ Build started: Project: Game1, Configuration: Debug Win32 ------
1>Main.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABVString@1@IABUContextSettings@1@@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main
1>C:\Users\Gaylord\documents\visual studio 2010\Projects\Game1\Debug\Game1.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



When changing "Enable Incremental Linking" to "Yes (/INCREMENTAL)"

I get this error

1
2
3

1
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Any ideas on what I can do? :S
Last edited on
For the first set of errors, you need to link to the .lib file.

Go in your project settings, in the linker section -- under "input", add:


sfml-graphics-d.lib
sfml-window-d.lib


For Release build, you'll need to add the same ones, but remove the -d

sfml-graphics.lib
sfml-window.lib





For the second error... it looks like a file got corrupted. Just do a clean and rebuild.
I did link everything of that before I started this code.

I first tried with SFML 2.1, but it didn't work
then I degraded from 2.1 to 2.0, made a new project, did everything again, linking and that,

Still gets the same error..
I don't know what to tell you... you must not be linking properly, because that's the only thing that could cause those errors.

Instead of doing the link in the project settings, you can do it right in the cpp file with a pragma directive:

1
2
#pragma comment(lib,"sfml-graphics-d.lib")
#pragma comment(lib,"sfml-window-d.lib") 



Or... you can do what I do and just make a separate sfml.h header file that includes all the normal SFML headers and has pragmas to link to all the libs. That way I never have to deal with this link stuff.

Note I prefer the static libs to the dyanmic libs on windows:
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

#pragma once
#ifndef SFMLFULL_INCLUDED
#define SFMLFULL_INCLUDED

#define SFML_STATIC
#define GL_GLEXT_PROTOTYPES

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#if defined(_DEBUG) || defined(DEBUG)
    #pragma comment(lib,"sfml-graphics-s-d.lib")
    #pragma comment(lib,"sfml-audio-s-d.lib")
    #pragma comment(lib,"sfml-network-s-d.lib")
    #pragma comment(lib,"sfml-window-s-d.lib")
    #pragma comment(lib,"sfml-system-s-d.lib")
    #pragma comment(lib,"sfml-main-d.lib")
#else
    #pragma comment(lib,"sfml-graphics-s.lib")
    #pragma comment(lib,"sfml-audio-s.lib")
    #pragma comment(lib,"sfml-network-s.lib")
    #pragma comment(lib,"sfml-window-s.lib")
    #pragma comment(lib,"sfml-system-s.lib")
    #pragma comment(lib,"sfml-main.lib")
#endif


#endif // SFMLFULL_INCLUDED 
Topic archived. No new replies allowed.