How to make a C++ program look for DLLs?

I want to be able to store DLLs in sub-folders without the EXE complaining about a missing DLL. How do I make the EXE look in a sub-folder, such as "DLLs"? If this has anything to do with it, my IDE is Code::Blocks.


To make this work with explicit loading (LoadLibrary/GetProcAddress) is easy enough. You are in control of the binding process and simply pass the full path to LoadLibrary.

For implicit loading you are at the mercy of the system. Whilst you could augment the PATH variable this is extremely draconian. Faced with the choice of putting all DLLs alongside the executable or modifying PATH, I would always choose the former.

There is also the option of DLL redirection but even Microsoft seem to advise you to place your DLLs alongside your executable rather than use redirection.

There are ways to do this via manifests or redirection, but these are pretty complicated.

I would recommend that instead, you use a structure as follows:


In the above example your real application is myapp_internal.exe, and it goes in the DLL sub-folder, so that all the DLLs can be located correctly. The myapp.exe binary is just a stub application that executes myapp_internal.exe.

I hope this helps!

Need Your Help

Executable fails with weird exception

c# .net ilmerge

I am using ILMerge and Quartz.NET in a C# .NET 4.0 Windows Service application. The app runs fine without using ILMerge, but now that we're nearing shipping release, I wanted to combine all DLLs in...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.