SFML community forums

Help => General => Topic started by: rogeriodec on May 20, 2018, 05:18:59 am

Title: [SOLVED] Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 20, 2018, 05:18:59 am
I installed Visual Studio 2017 and downloaded SFML Visual C++ 15 (2017) - 32-bit package.
I do not know if they are compatible, but as I did not find the updated SFML package for Visual Studio 2017, I downloaded this one myself.
I configured it according to the video
https://www.youtube.com/watch?v=_9yem5dJt2E
... because the https://www.sfml-dev.org/tutorials/2.5/start-vc.php tutorial was not clear about using the files with "-d" end and was not working.
But I used the example code on this page and when compiling I get the errors:
Code: [Select]
1>ConsoleApplication2.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>ConsoleApplication2.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)

My question is whether these errors have to do with some mismatch between the installed versions or if the problem is another.
I wanted to avoid the ordeal that is installing SFML manually.
Title: Re: Visual Studio 2017 and SFML
Post by: eXpl0it3r on May 20, 2018, 07:57:07 am
Did you define SFML_STATIC yet link SFML dynamically?
Title: Re: Visual Studio 2017 and SFML
Post by: rogeriodec on May 21, 2018, 12:35:32 am
Attached some screenshots.

Is something missing?
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: eXpl0it3r on May 21, 2018, 12:49:05 am
As suspected, you defined SFML_STATIC, yet you're linking SFML dynamically.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 21, 2018, 01:01:36 am
Thanks, but could you be clearer?
I do not know what to do. What should I correct exactly?
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: Gamachara on May 21, 2018, 05:11:22 am
The SFML_STATIC is here. SFML_STATIC tells Visual Studio you should have resources for the static version. You're not linking statically, you're linking dynamically and have the dynamic resources available. Get rid of SFML_STATIC.

Make sure you do this for all build configurations.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 21, 2018, 05:28:13 am
Thanks, now the build does not generate any more error, but when running the program it requires that I copy all the DLLs from C:\ SFML-2.5.0\bin to the folder of my compiled .exe (ConsoleApplication2\Debug).
I did not want to ever have to do this.
How can I generate an .exe without ever having to copy the dlls to the project folder?
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: G. on May 21, 2018, 08:55:59 am
https://www.sfml-dev.org/tutorials/2.5/start-vc.php
Quote
If you want to get rid of these DLLs and have SFML directly integrated into your executable, you must link to the static version. Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d.lib" for Debug, and "sfml-xxx-s.lib" for Release.
In this case, you'll also need to define the SFML_STATIC macro in the preprocessor options of your project.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: billarhos on May 21, 2018, 10:04:49 am
In windows system you can gather all sfml dlls (and not only), debug and release in one folder and add this path folder in "environment variables" into "system properties" in User "Path".

For instance "D:\ThirdParty\dlls"

Then visual studio automatically detects this path and no longer have to add those dlls in release or debug folder.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 21, 2018, 06:40:52 pm
Thank you. Now I understand what the static and dynamic library is.
But the tutorial https://www.sfml-dev.org/tutorials/2.5/start-vc.php talks about the static dlls, the link available for download https://www.sfml-dev.org/files/SFML-2.5.0-windows-vc15-32-bit.zip brings only dynamic libraries.
Is not this contradictory? Should not the static DLLs be included together?
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: eXpl0it3r on May 21, 2018, 07:35:34 pm
But the tutorial https://www.sfml-dev.org/tutorials/2.5/start-vc.php talks about the static dlls
The tutorial doesn't talk about static dlls, because that's not a thing.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 21, 2018, 08:50:46 pm
The tutorial doesn't talk about static dlls, because that's not a thing.

From https://www.sfml-dev.org/tutorials/2.5/start-vc.php:
Quote
If you want to get rid of these DLLs and have SFML directly integrated into your executable, you must link to the static version. Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d.lib" for Debug, and "sfml-xxx-s.lib" for Release.
In this case, you'll also need to define the SFML_STATIC macro in the preprocessor options of your project.

I do not want to argue, I just want to solve the problem. The file provided does not have the static DLLs. How to solve this?
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: eXpl0it3r on May 21, 2018, 11:09:05 pm
Well it's written right there and it doesn't mention anything with static DLLs.
There isn't much more I can do to help you with reading the text, but let me try...

Quote
If you want to get rid of these DLLs [meaning you don't want to use DLLs] and have SFML directly integrated into your executable, you must link to the static version. Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d.lib" for Debug, and "sfml-xxx-s.lib" for Release. [meaning if you want to link SFML statically, you need to link against the .lib files that have the -s suffix]
In this case[meaning IF and only IF you're linking SFML statically], you'll also need to define the SFML_STATIC macro in the preprocessor options of your project.

So if you want to solve the problem, then do what I have by now pointed out for the third time, do not add SFML_STATIC to your project file if you're not linking statically, which you aren't based on your screenshots.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: c0d3r9 on May 21, 2018, 11:16:46 pm
And my two cents.
@rogeriodec
There exists no static DLL´s.
DLL´s are dynamical loaded.
The other "static DLL" that you mean are libraries.And DLL´s are libraries too.
static libraries are included in your app.
DLL´s are seperate libraries wich you provide with your app.

It´s your choice what you use.
Take only one way.

And i must say, because i´m a non pro c++ coder especially with sfml, all infos are on this website.
I build sfml every time from sources with cmake and vs/mingw and i do this never before.
All infos are there.

@eXpl0it3r: a simple thx
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: jamesL on May 24, 2018, 10:32:37 am
So if you want to solve the problem, then do what I have by now pointed out for the third time, do not add SFML_STATIC to your project file if you're not linking statically, which you aren't based on your screenshots.

that doesn't solve his problem at all

he specifically states he doesn't want to have to move dlls into the exe folder

he WANTS to link statically and he doesn't know which "things" to include in the project

you're getting hung up on the phrase "static dlls"  when its obvious he doesn't know the correct terminology

@rogeriodec
when it says this
"If you want to get rid of these DLLs and have SFML directly integrated into your executable, you must link to the static version. Static SFML libraries have the "-s" suffix:"

its not saying "if you want to get rid of these dynamic DLLS ... you must link to the static version of the dlls"

its saying "if you want to get rid of the DLLs completely then use the static libs"

sfml-window-s.lib
sfml-system-s.lib

but you'll also have to link to
opengl32.lib
freetype.lib

and other stuff as listed in the chart




Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 29, 2018, 09:38:09 pm
I was able to install the Visual C++ 15 (2017) - 64-bit with static libraries.
Debug is working fine.

But when compiling a "release", I get:

Code: [Select]
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::CircleShape::CircleShape(float,unsigned __int64)" (__imp_??0CircleShape@sf@@QEAA@M_K@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UEAA@XZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QEAA@VVideoMode@1@AEBVString@1@IAEBUContextSettings@1@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QEAA@EEEE@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::display(void)" (__imp_?display@Window@sf@@QEAAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QEAA_NAEAVEvent@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QEBA_NXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::close(void)" (__imp_?close@Window@sf@@QEAAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::Color const sf::Color::Green" (__imp_?Green@Color@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QEAAXAEBVDrawable@2@AEBVRenderStates@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QEAAXAEBVColor@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Shape::setFillColor(class sf::Color const &)" (__imp_?setFillColor@Shape@sf@@QEAAXAEBVColor@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QEAA@PEBDAEBVlocale@std@@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QEAA@III@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::CircleShape::~CircleShape(void)" (__imp_??1CircleShape@sf@@UEAA@XZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::~String(void)" (__imp_??1String@sf@@QEAA@XZ)
1>C:\Users\Rogerio\Desktop\c++\Visual Studio\sfml-vc15-64\x64\Release\sfml-vc15-64.exe : fatal error LNK1120: 17 unresolved externals
1>Done building project "sfml-vc15-64.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is my configuration to Release.
What is wrong?

(https://i.imgur.com/QsMFRKd.jpg)
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: eXpl0it3r on May 29, 2018, 10:04:25 pm
You didn't define SFML_STATIC as mentioned in the tutorial.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 29, 2018, 10:58:03 pm
Of course, I had put SFML_STATIC only in the debugger. Now it's ok.
Thank you!  :)

Just one more thing:
In order to not generate the console screen in the release version, under "Linker-> System-> Subsystem", I switched from "Console (/ SUBSYSTEM: CONSOLE)" to "Windows (/ SUBSYSTEM: WINDOWS)".
But with this latter option, it generates this error when compiling:

Code: [Select]
1>------ Build started: Project: teste, Configuration: Release x64 ------
1>MSVCRT.lib(exe_winmain.obj) : error LNK2001: unresolved external symbol WinMain
1>C:\Users\Rogerio\Desktop\c++\Visual Studio\teste\x64\Release\teste.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "teste.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How to solve this?
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: eXpl0it3r on May 29, 2018, 11:43:47 pm
You'd link sfml-main which will implement WinMain() and call main(). :)

I think it's also mentioned in tutorial or at least in the FAQ.
Title: Re: Visual Studio 2017 and SFML 2.5.0
Post by: rogeriodec on May 29, 2018, 11:55:08 pm
Perfect!
Thank you very much.