1

I tried creating an empty C++ project in VS 2019 and I opened Project Properties where I found that there was a list of import libraries that VS was adding as "Additional Dependencies"

kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

These seem to be related to the Windows API and not the standard C++ library. Are these required for a console application that doesn't involve any Windows API calls? Why are these added by default? Also, where are these files located?

  • 3
    See [Why do we need to link kernel32.dll, user32.dll, etc... in Windows C++?](https://stackoverflow.com/questions/39812395/why-do-we-need-to-link-kernel32-dll-user32-dll-etc-in-windows-c). Not all of those libraries get used in all cases. To check what's actually linked into your .exe run `dumpbin /imports`. – dxiv Nov 25 '20 at 03:59
  • @dxiv Why does the program link properly even when I remove those names from the Additional Dependencies and when I run `dumpbin \imports`, I can see kernel32.dll being loaded – Vishal Subramanyam Nov 25 '20 at 04:19
  • `kernel32` is an implicit dependency, and there is no price paid for it since `ntdll` and `kernel32` are mapped into the memory space of any windows app anyway. – dxiv Nov 25 '20 at 04:29

1 Answers1

2

Here's a quick rundown of what thes libs are for:

  • kernel32 : Process and thread management, file and device I/O, memory allocation (keep this, the C and C++ runtime libraries and compiler-generated code uses it)
  • user32 : Window and menu management (keep this if using GUI, can remove for console apps) The base set of widgets (= predefined window classes, like buttons and checkboxes and scrollbars) are here.
  • gdi32 : Drawing (keep this if using custom rendered graphics, can remove if just using widgets)
  • comctl32 : Fancy new widgets, like trees, listviews, and progress bars
  • winspool : Advanced usage of printing beyond what GDI covers.
  • comdlg32 : Common dialogs, like Open and Save File Dialogs
  • advapi32 : Registry support, user account and access control, cryptography. I usually end up needing this one, your needs may differ.
  • shell32, shlwapi : Taskbar and notification tray UI and more helper functions, like predefined folders and path manipulation functions. Often useful, but many applications won't need it.
  • ole32, oleaut32 : OLE is the basis for ActiveX, DCOM, etc. Many of the newer OS APIs are COM objects, so you probably need to keep this.
  • uuid : Advanced OLE usage, probably not needed.
  • odbc32, odbccp32 : Database access using a very old and unfriendly API. I always remove these.

These are the libraries that interface with Windows. Of course, if you do not use the operating system function directly, you can remove them. However, It is not recommended to remove them. If you want to prohibit their use, you could add the lib in Prperties->Linker->Input->Ignore Specific Default Libraries.

You do not need to worry about it. The .libs are really small, and the .dlls they refer to are already present as part of your Windows installation.

Barrnet Chou
  • 1,738
  • 1
  • 4
  • 7