SFML community forums
Help => General => Topic started by: Kuker on January 31, 2015, 05:41:58 pm
-
Hello there! I have a problem with linking static libraries in Visual Studio 13. I've read, that now i have to link (type them in ProjectProperties->Linker->Input->Additional Dependencies) all libraries. The problem is, i still get linker or IntelliSense errors. My question and request for you, is that you should add in tutorial what EXACTLY should be typed in there to get static libraries ;). For many new people this is very hard, as it is for me, cause i don't really know if i should type then in All Configurations, or only in Debug or somewhere else.
Thank you in advance for any help, and sorry if I wrote something wrong.
Cheers!
-
First of all; you can mostly ignore intellisense errors. Intellisense uses a completely different parser than the actual compiler. Intellisense can help sometimes provide "tips" but it doesn't have anything to do with what the real compiler actually does with your code. It's just a "helper".
As far as linking libraries goes; any C++ developer worth his salt should know how his toolchain works. This includes knowing the rules the linker follows when linking static and/or dynamic libraries and how to configure that in his buildsystem of choice. The basic rule is; depending libraries need to be linked before the libraries providing needed facilities.
Sure, the tutorials could maybe spoon-feed info a bit more, but in the long term you still need to learn this stuff for yourself.
In any case; this is just my personal opinion.
-
Thank you for your reply. So, you're telling me to check in what order are the libraries linked? I thought it doesn't matter in VS13 :).
-
Library linking order matters. Yes.
As does explicitly mentioning all needed libraries to the linker.
You need to mention all needed libs and you need to mention them in proper order.
Some compilers/linkers may relax the rules and pull in stuff for you implicitly, but don't count on it.
And don't forget that debug and release versions of a library are not the same. You sometimes (often) need to link different libs for debug and release builds...
-
So if I want to use these three modules (i think this is their definition): sfml-system-s, sfml-windows-s, sfml-graphics-s, I have to link these things aswell: winmm.lib, opengl32.lib, gdi32.lib, glew.lib, freetype.lib, jpeg.lib?
-
For static linking that looks about right (on my phone atm, can't check) - why don't you just try? ;-) and/or read up on the details ;)
Edit: I admit that I'm probably not the best guy to help with this since I tend to assume that people have the basics already worked out. And I'm maybe not very good at being considerate and helpful. More of an old arrogant ass. - sorry.
-
Well, it does not work :/. That's why i would like someone to tell me what and where to type.
-
Because the list here (http://www.sfml-dev.org/tutorials/2.2/start-vc.php), right after the red box that explains how to link static is not clear enough? I don't see how it could more clear.
-
Believe me, I've read it and I link all other libraries aswell and it still doesnt work. I don't know in what order should i type them to VS.
-
Why dont you try linking dynamically for now? If that works, then you know that you are doing something wrong when you are linking statically.
-
I think the problem is solved, it wasn't the compiler fault, just an error in code. But now when i try to debug it, i get an Unhandled Exception about ntdll.dll. Got any idea what it causes? It pauses on the line "sf::RenderWindow window;". I'll add, that it compiles without any errors (except those of intellisense).
-
sfml-system-s, sfml-windows-s, sfml-graphics-s
Are you trying to compile in debug mode because these are the release versions.
Have you added the static definition to the preprocessor list (as per the VS tutorial)?
Does the same code compile fine with dynamic libraries?
-
Yes yes I've already fixed that. The code works and debugs with dynamic libraries, with static ones it compiles, but when i try to debug it stops as i mentioned above. I use correct libraries, -s-d for debug and -s for release, aswell as other libraries (winmm, opengl32 etc.) in "All Configurations".
-
It runs fine statically in release mode but not in debug mode?
-
"The program has stopped working" - it says when i start it without debugging.
Problem solved: works ok when i declare sf::RenderWindow window in game.h, instead of putting it globally in game.cpp. Thanks guys for your help.
-
Just so we can be sure that we know what you're linking, try these:
Debug
opengl32.lib;jpeg.lib;freetype.lib;glew.lib;winmm.lib;gdi32.lib;sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;
Release
opengl32.lib;jpeg.lib;freetype.lib;glew.lib;winmm.lib;gdi32.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib;
Make sure you're defining static in both debug and release (or on "all configurations").
One other thing...
By any chance, are you declaring your sf::RenderWindow with the static keyword?