Board index » cppbuilder » How do I static link a .dll?

How do I static link a .dll?

Hello,
I would like to statically link a .dll file into my project.
I will only be using a few functions in the .dll but cannot
figure out how to statically link it (I'm using BCB4).
I have created a .lib file using implib on the command
line, but it is still asking me for two or three .dll files.
Perhaps I'll have to statically link more that one .lib
file in the end, but can someone tell me how to statically
link just one?

Thanks.
Chris

 

Re:How do I static link a .dll?


Quote
On Sun, 8 Aug 1999 10:44:08 -0600, "Chris O'Gorman" <chri...@swcp.com> wrote:
>I would like to statically link a .dll file into my project.

You can't *statically* link a *dynamic* link library (dll).
You can only statically link static libs. Static libs have
relocatable object code, dlls have absolute executable
code. It's like the difference between an obj file and an
exe file.

Quote
>I have created a .lib file using implib on the command
>line, but it is still asking me for two or three .dll files.

The lib file created by implib is an *import* lib for the dll.
It is not a static lib. It merely allows the linker to resolve
references to functions in dlls automatically. You'll still
need the dlls at runtime.

For the RTL, use the menu Option for static linking,
and turn off the option to use packages. This will
result in the static libs being used and the RTL code
will be statically bound to your exe. If this is a 3rd party
dll, you can't link it statically - you'll always need the dll,
unless the 3rd party supplies a static lib as well.

--
Wayne A. King
(ba...@torfree.net, wayne.k...@ablelink.org,
 wak...@idirect.com, Wayne_A_K...@compuserve.com)

Re:How do I static link a .dll?


Quote
On Sun, 8 Aug 1999 10:44:08 -0600, "Chris O'Gorman" <chri...@swcp.com> wrote:
>Hello,
>I would like to statically link a .dll file into my project.
>I will only be using a few functions in the .dll but cannot
>figure out how to statically link it (I'm using BCB4).
>I have created a .lib file using implib on the command
>line, but it is still asking me for two or three .dll files.
>Perhaps I'll have to statically link more that one .lib
>file in the end, but can someone tell me how to statically
>link just one?

The VCL DLLs can be either statically or dynamically linked (by changing the
options in the Project Options). Windows DLLs cannot. 3rd party libraries or
objects will sometimes be provided both as a DLL and a statically linked
library, so that you can link whichever way you wish. If the DLL is your own
code, you can recompile it as a static library.

I think you may have misunderstood the nature of IMPLIB. The IMPLIB program
creates a .lib file from a DLL, but this .lib file only contains information to
allow your code to link in stubs. These stubs, when called by your program, will
dynamically link to the DLL at run time. All DLLs (including the Windows DLLs
themselves, but in this case the process is quite transparent) need a lib file
containing these stubs to be linked in to any program which uses them. The lib
files are naturally much smaller than the DLLs themselves!

Pete Barrett

Other Threads