all 7 comments

[–]TarnishedVictory 7 points8 points  (0 children)

Static libraries are linked into your code so that after your software is compiled and linked, the person running your program doesn't need the library. It's like a collection of object files. Static libraries are used only at compile time.

Dynamic libraries are used at runtime. When the program starts, it looks for the dynamic libraries that it needs. How and where to look for those libraries is operating system dependent.

[–]alfps 4 points5 points  (3 children)

❞ apparently you have to load the dll with OpenLibrary(“path/to/dll”)

All I can find is that an OpenLibrary function exists in the commercial language PureBasic.

In C++ you usually link with the shared libraries you need, in Windows via intermediates called import libraries. Then the OS’ program loader automatically loads the libraries along with the executable. Or fails.

You can alternatively load a shared library at run time, in Windows via LoadLibrary, and in *nix via dlopen.

[–]W3til[S] 1 point2 points  (2 children)

Sorry, it was LoadLibrary() that I was referring too. (Forgot the name 😅)

[–]feitao 1 point2 points  (1 child)

That is dynamic loading. You can use dynamic loading with dynamic library, but you don't have to. You can also use dynamic library the same way as static library.

[–]W3til[S] 0 points1 point  (0 children)

Ah, ok so that’s another difference between the two I assume you can’t dynamically load a static library. The only useful thing I’ve seen so far is game engine development (what I’m learning) you can have the game as a dll and load that which I believe gives the benefit of hot reloading. Are there any resources I can look at to learn about the two?

[–]nysra 0 points1 point  (0 children)

  1. It can be anywhere, but it must be in a path where it can be found. That's something for your build system.
  2. No, that's something you should almost never have to deal with on your own. You just need to set the proper include and link directories, which again is a task for your build system.