VC++ resources in a static library

sharkin picture sharkin · Feb 10, 2009 · Viewed 25.1k times · Source

Is it possible to build resources into a static library and reuse them by simply linking with the library?

I'm primarily thinking about the case where you call a function in the library which in turn accesses resources.

Answer

Dimitri C. picture Dimitri C. · Oct 27, 2009

The only thing you need to do to use resources (images, dialogs, etc...) in a static library in Visual C++ (2008), is include the static library's associated .res file in your project. This can be done at "Project settings/Linker/Input/Additional dependencies".

With this solution, the resources of the static library are packed into the .exe, so you don't need an extra DLL. Regrettably, Visual Studio does not include the .res file automatically as it does for the .lib file (when using the "project dependencies"-feature), but I think this small extra step is acceptable.

I have looked for a very long time for this solution, and now it surprises me it is that simple. The only problem is that it is totally undocumented.