Take the 2-minute tour ×

I'm trying to understand what exactly all of these are and how they relate to each other (and most importantly, how to install them).

From what I've read, LIBs are libraries linked during the compilation of my project and DLLs are libraries linked during the runtime of my project.

So for me to use a LIB, I have to have the actual .LIB file somewhere in my computer, go to Project -> Properties -> VC++ Directories and add the path to the file in the Library Directories, and after this I have to go to Linker -> Input -> Additional Dependencies add the .lib name in there, and finally I need to type #include in my code, right?

So, some questions:

  1. When I finish and build the release of my program, will the .exe only run if the target platform has the .lib installed in their PC as well? If yes, what steps do I need to do to make sure the .lib goes with the .exe?

  2. When I get the source of a open source project, if I add them (using Add Existing Item...) to my project, can I use them just by using #include as if the files were mine and it would be the same as having the .lib installed? Or do I need to install the .lib file and still use these source files?

  3. I have a project using OpenGL and I linked to glew32.lib, but I don't have the lib or any new directory added in the VC++ Directories, so I think this means I must've installed the .lib in the system folder or somewhere where the Visual Studio won't ask for another directory, should I worry about this when releasing a project?

  4. How the above questions relate to DLLs and is there any reason why should I use DLLs over LIBs or the other way around?

I'm starting to use more and more libraries and I noticed I just dragged, copied and included it everywhere so I could use them but never really understood how they "fit" in the project. Especially those open source libraries where they provide so many files and I don't really know what to do with them...

share|improve this question

1 Answer 1

up vote 1 down vote accepted
  1. You don't need to have LIB files among with your EXE file for running in other computers, LIB files are static files and DLL files are dynamic. So when you compile all static codes will be included in your EXE file, but DLL files will be loaded and used dynamically in runtime, so you just need to have your DLL files with your EXE file, so your code will work and run properly in other computers.

  2. Just adding another project is not enough, they'll be compiled to LIB so in your END project, you need to add output of other project's LIB file as input to your final project. Also you'll set solution project build order.

  3. No, that's OK. It seems you've put LIB files in right folder and you don't need to have LIB file with your EXE file to run it in other computers.

  4. DLLs are dynamic libraries, so you need to have them with your application. Installers usually install EXE files with DLL files in same folder so your app will run properly, but no need to include LIB files at all.

Also you can include LIB files with code like:

#pragma comment(lib, "glew32.lib")

So you don't need to do it in project settings, but assuming you have your LIB file in LIB directory path.

Using DLL files can be done in two ways: One is linking your application to DLL file and having DLL file's function entry in your EXE file's import table: like using

#include <windows.h>


GetWindowsDirectory(windir, MAX_PATH);

So you'll have GetWindowsDirectory API entry in your EXE file's Import Table.

Also you can do it dynamically:

hinstDLL = LoadLibrary("kernel32.dll");
if (hinstDLL != NULL)
    func_GetWindir = (DLLPROC) GetProcAddress(hinstDLL, "GetWindowsDirectoryA");

There is not much difference, just: In first method, as it's in your EXE file's Import Table, if there was no kernel32.dll or there was no GetWindowsDirectory entry in kernel32.dll, your EXE will not run at all from beggining, it will show a critical error and will not run, but in dynamic way (second way), you app will run, but as soon as your code try to use GetWindowsDirectoryA API, it will fail.

share|improve this answer
Regarding #4, I've managed to compile OpenAL and freealut (two open source libs) and they compiled a .DLL as well, and if I only link/add the folders in my project it says the project can't be started because the LIBRARY.DLL is missing from the computer. Does this means I'll have to somehow send these .DLLs with my .EXE too? I managed to start the project by putting the .DLLs in the Windows/sys32 and sys64 folders, but is there a way to put them ONLY in the project folder? –  Danicco Feb 17 at 22:52
You can put them in same folder of EXE file or in System32 or Windows folder, don't worry, put them in same folder of your EXE file and it will work –  72DFBF5B A0DF5BE9 Feb 17 at 23:03

Your Answer


