I've got a C++ Visual Studio (VS) project that I want to build out to a DLL so that other VS projects can link it. Actually doing this doesn't seem complicated to me but the devil is in the details. For example, if I want only some of the public
methods, class
es, etc. in the DLL to be accessible outside of the DLL's internal workings, I'm seeing conflicting answers online as to how this is achieved.
Given this, I provide my understanding of how DLLs can be built in VS to be used by other VS projects. Do I have this correct?:
The DLL is the entire VS project compiled to machine code. At this point, the concept of methods,
class
es, etc. fade away (this I'm sure of, just stating clearly for later). The LIB that gets generated with a DLL and that will be used as an additional dependency in a VS project linking in a DLL acts as a redirector to data in the DLL. Whatever methods (and ONLY methods) one adds__declspec(dllexport)
to in the VS project of the DLL are all that will be included in the LIB which will create a compile "firewall" for users of the DLL such that users can technically include any.h
and.cpp
files they want from the include directory related to the DLL but they won't actually be able to execute anything from those files unless it is specified in the LIB file. This means that anypublic
methods in the DLL that aren't a part of the LIB are effectively locked to only being accessed by other data in the DLL. If one needs control over the accessibility of members,class
es, etc. through a LIB file then a more intentional design choice of PIMPL implementation will be required. When linking the DLL into a new VS project, one must also link in any and all DLLs that the compiled DLL used (e.g. GLFW).
I do apologize for structuring my question to be so loaded, but advice to make separate posts for each facet of this question as I have received in the past is tricky for an account of my standing as I have to wait ~90 minutes between each thread I post and by that point I've got other obligations to tend to.
Many thanks for reading!
No. You can also use a .def
file to specify exported functions, even if that's not as common.