In a nutshell: How can I statically link .dll files into my programs executable? I know it's possible, just have never done it before. I know there is also some issues that arise in doing so ( as well as bloating the executable's size ) but I'm still game for it.

Also, if that is just way to problematic, could someone at least tell me a way to link to the .dll files I need without having them directly in the same directory as the .exe file? The only reason I'm wanting to either statically link or organize these files is that there are several very small .dll files that I'm using, and I don't want the user to have to look at the directory where the .exe is and have to skim through ( a bit exaggerated ) 30 .dll files just to find the executable. It's also good to separate the files.

Any help would be great! I've been trying to use several other compilers and IDE's lately for exposure purposes ( I've also been doing Command line/Shell compiling/linking lately for those same reasons :)).

Recommended Answers

All 4 Replies

If you use MinGW then this thread may help you. Go to project options, linker tab, and add -static flag. But that flag didn't seem to make any difference with my small test program.

>>tell me a way to link to the .dll files I need without having them directly in the same directory as the .exe file

If they are not in the same directory as the *.exe file then they must be on one of the directories in the PATH environment variable. On Windows 7 (probably earlier versions of Windows too) click Start --> Control Panel. Then select System icon. In there you will find options to view and edit environment variables, including PATH. You can add another directory to the PATH or copy the dlls into one of the existing directories. Adding your own directory is ideal so that you don't clutter up someone else's directories with your dlls.

FWIW, DLL's are "Dynamic Link Libraries". They are NOT suitable for static linkage. For Windows, you need to link *.lib files, not *.dll files... They may reside in directories other than where you find the .dll ones.

Another simple solution to not cluttering your main install directory, and I believe this solution is pretty frequent, is to put your "real" executables and DLLs in a subfolder (like "bin") and then write a simple "launcher" executable to put in the main install directory, that launcher just starts the "real" executables found in the subfolder. This way you hide the ugly stuff and you don't pollute the client's system32 directory.

As for turning a _Dynamic Link Library_ into a static library, I have doubts that this is even possible (maybe it is, but I wouldn't know how). Normally, under Windows, the .dll is paired with a .lib static library, and the .lib is used just to associate the symbols for loading the DLL (i.e. it won't put the content of the .dll inside the .exe, you will still need the .dll to execute the program).

If you have the source for the DLL(s), then I suggest you compile those sources as static library instead, then, all the code will get bundled in the executable, dependence-free, but larger .exe file.

Thanks everyone! Very helpful!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.