Sign in to follow this  

static library vs. dll

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, i am trying to develop a kind of library for my games. it looks as if there are two possibilities: dynamic library and static library. are there any main differences other, that with the static library i have to add the *.lib to the linker? all my projects are in the same VS-solution, so is it possible to automatically build the games and the libraries with SL and DL ? thanks! also, does anyone of a tool that attaches a dll to an exe? thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by ehmdjii

also, does anyone of a tool that attaches a dll to an exe? thanks!


Build process will "attach" a static library during linking phase.
DLLs are stand-alone and intended to be shared.

Share this post


Link to post
Share on other sites
The lib file can be one of two types.

Type 1: Statically linked. The lib file houses all of the code for the library. When you link to this file, the functions will be stored inside your executable. No DLL is necessary.

Type 2: Dynamically linked. This lib is a helper so that you don't have to manually "hook up" your code to the DLL functions. It basically tells the compiler to do it for you. This type just tells the operating system that you're using x.dll and need it to bind the functions for you. This type requires that the DLL be installed on the user's machine.

You will have to link either type of library no matter.

Another way to utilize a DLL is with the LoadLibrary() function and it's other routines to bind functions at run time. Don't do it if you have a .lib available.

Happy coding.

Share this post


Link to post
Share on other sites
thanks for the explanation. how do i define which kind of lib i want to create in Visual Studio?

also, does anyone of a tool that attaches a dll to an exe? i heard that such a tool exists, but havent found it yet. thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by ehmdjii
also, does anyone of a tool that attaches a dll to an exe? i heard that such a tool exists, but havent found it yet. thanks!

There is no 'tool' to attach a DLL to an executable, nor is there a tool to attach a static lib to it.

A DLL is either automatically attached by the runtime environment at startup (which is called implicit dynamic linking), or it is attached by yourself manually somewhere in your code (explicit dynamic linking). The former is easier to achieve, and done by simply linking your project with the import lib file associated with the DLL.

Share this post


Link to post
Share on other sites
Usually the main benefit of a DLL is that it keeps your code separated in several files, which means if you need to release updates you only have to replace the affected DLL's. They're also useful for apps that utilize some sort of plug-in system, where at run-time the app can be configured to load a certain DLL to obtain new functionality. You can't do that with a static lib, since it's compiled into the .exe

Share this post


Link to post
Share on other sites

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this