Reputation: 845
I have a problem with statically linking dll files into project. I'm using Builder C++ 6.
I've unchecked:
Project \ Options \ Packages -> Build with runtime packages
Project \ Options \ Linker -> Use dynamic RTL
Project \ Options \ CodeGuard -> CodeGuard Validation
I've also added dll files using Project Manager:
myProject \ Add -> myFile.dll
Of course i've rebuild the project after all changes and it still asks for some dll files at runtime. What have i omitted?
Upvotes: 2
Views: 2049
Reputation: 596823
When you statically link to a DLL, what is really happening is that the compiler detects which DLL functions your code is calling and sets up stub pointers that the linker then inserts into your application's IMPORTS table. At runtime, when your application is run, the OS loader will first patch the IMPORTS table (amongst others) by loading the referenced DLLs into memory and then updating the function pointers as needed. This happens before any code inside the application begins running. If the loader cannot resolve a reference, it will display an error and kill the process. The DLL itself is not compiled into the application itself. It must remain as an external file (so it can be shared with multiple applications/processes, if needed) and be installed where the OS loader can find it. This is how DLLs are designed to be used. No amount of changing project options will change that.
If you want your library code to be compiled directly into the application, then you need to create a Static Library instead of a DLL.
Upvotes: 2
Reputation: 15232
Instead of adding your own dll, see here how to create your own static library, which you can add to your project. It is not possible to genereat a static library if you just have the dll. You can only generate an import library from a dll, and for that you will need to distribute the dll too.
Upvotes: 0