1

I'm currently trying to get SFML setup in Visual Studio. I've been following the tutorial here: http://www.sfml-dev.org/tutorials/2.4/start-vc.php

I've gotten to the point where I've specified the library location and which .lib's I want to use.

However, I'm confused at the part where it states that the previous actions have just setup the project to load the libraries dynamically. This confuses me. Have I not just specified the .lib files? And aren't .lib files static libraries? Why would the project be configured to dynamically load a library after specifying static lib files?

Furthermore, when I go to run the demo project. It states that the dll's can not be found...

The tutorial then goes onto state that if you want to statically link to the libraries, you have to specify different .lib files and define a preprocessor macro.

So my question: How exactly does Visual Studio decide whether or not the library you pointed to will be loaded statically or dynamically? It seems like if I wanted to load a library dynamically, I would have to point to directory containing dlls, not libs.

Any help?

Izzo
  • 4,461
  • 13
  • 45
  • 82

2 Answers2

2

VStudio doesn't get to decide how to load (or better: let's say use) a certain library. It uses it as the library was built (static or dynamic). When building a library with VStudio the output will (almost) always contain a .lib file.

Check the 2nd bullet of [SO]: Errors when linking to protobuf 3 on MSVC 2013 (@CristiFati's answer), that briefly describes the difference between the 2 library types.
For extended information on dynamic link libraries, check [MS.Learn]: Dynamic-Link Libraries. The .lib files are used by VStudio when building your application (at link time to be more precise).
Now, if everything goes well, your application is built (you'll have an .exe file in your project output directory).

When running (and debugging) that executable, if it uses dynamic libraries, those libraries .dll files must be present in one of the locations specified on [MS.Learn]: Dynamic-Link Library Search Order (to keep things simple, I'd suggest to copy them in the same folder as your .exe file - note that it's for demonstrating purposes only, it shouldn't be way of deploying apps).

CristiFati
  • 38,250
  • 9
  • 50
  • 87
0

A library is defined as static or dynamic when it's built and the SFML website provides both versions (You can specify which you want when building from source).

When you run the application, it will look in the system and its own directory for the dynamic library file for SFML.
You can use xcopy in the PostBuild project settings to copy the .dlls you need into the target directory. For example, this will copy all debug .dlls into the directory with the .exe:

xcopy "$(SFML)\bin\*-d-2.dll" "$(TargetDir)" /Y /D

The process is the similar for Release builds, but you'll need a file to specify that you want to exclude .dlls ending with -d

Alex Meuer
  • 1,621
  • 3
  • 26
  • 37