Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Should it be possible to make a dynamic library that does not link with any static library?
Posted

Technically yes: but you must meet these points

  • your code must be self-cotained (no need to use language libraty functions
  • If you need some OS API, you must import dynamically the operating system DLL (via LoadLibrary and GetProcAddrss)
  • Your language must not require pre-initialization or post-termination code. (C++ is not suitable for that, unless disabling those features, but this means "no static and global objects", since they will not be properly constructed / deleted
  • Your compiler must be able to generate code forwatever construct (never translate it in some runtime-library function call: C++ sometimes require the CRT, C can do without it, but only in certain condiction: no FILE operation)


In other word, if the compiler requires part of the code to be "precomposed" and not "generated on the fly", it is quite hard to eliminate a runtime-library.

Note that -even if the CRT is linked as DLL- a import library is in any case needed, since you cannot load it in DllMain, since part of it must be executed before.
It is a damn "chicken and egg" problem!
 
Share this answer
 
Comments
Sauro Viti 11-Aug-10 5:05am    
Reason for my vote of 5
Good answer
Sauro Viti 11-Aug-10 5:07am    
Just a little thing: you said "if you need some OS API, you must import dinamically the operating system DLL (via LoadLibrary and GetProcAddress)", but to do it you should use LoadLibrary and GetProcAddress, then you should link against kernel32.lib
Emilio Garavaglia 11-Aug-10 15:50pm    
Yup! Another chiken and egg problem! :-)
CPallini 14-Aug-10 11:53am    
Maybe I'm wrong, but the using kernel32.lib to link against kernel32.dll doesn't appear 'static linking' to me, as far as I know you may only 'dynamically' link with the kernel library.
Emilio Garavaglia 15-Aug-10 9:10am    
Err ... we are messing up the terminology.
A LIB is a satic library.
A DLL is a dynamic library that can be loaded runtime (via LoadLibrary and obtaining function addresses with GetProcAddress) giving a dynamic binding
or by means of a LIB that redefines the functions in itself into stubss that load the DLL and bind "statically" the functions to its owns.

The linking of kernl32.lib is a static linking of a lib to OBJs to produce an exe. It is the LIB that loads the DLL and calls the DLL functions, not your OBJs, that call the static LIB functions.
Aren't, by default, DLLs as such?
 
Share this answer
 
Hm, a dll does not link to any static library unless you advise it to do so...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900