问题
I use msvc compiler now
I want to make linking libraries (lib, dll) which independen to the mvsvc version..
Is it possible to make the independent libraries?
回答1:
Static libraries - no. DLLs - yes, when the public interface is designed appropriately.
There are generally two ways to achieve that with a DLL:
The DLL exports a number of functions forming a C-style API, similar to Windows API. Those functions use only primitive types in their signature, and arrays and structures thereof (no C++ classes). Objects are represented by handles (cf.
HWNDorHDC) with a set of functions for manipulating those handles.The DLL is a COM server (or at least exports a COM-like interface). Basically, a factory function (in COM,
DllGetClassObject) that manufactures a pointer to an abstract class with no data members and all member functions pure virtual (commonly referred to as an interface). All access is by calling methods on these interfaces (which may in turn manufacture other interface pointers).
Another consideration you should pay attention to is resource management - in particular, but not limited to, memory management. You cannot assume that a memory malloced in the DLL could be freed in the client, or vice versa. You must ensure that resource allocation/deallocation never crosses module boundaries. It could be that the DLL never allocates memory that the client needs to free; or that the DLL exports a special function that the client should call to deallocate memory that the DLL allocated; or that the DLL uses facilities provided by the operating system (e.g. CoTaskMemAlloc / CoTaskMemFree in COM).
来源:https://stackoverflow.com/questions/21885909/how-to-make-libraries-independent-to-compiler-version