I'm planning to build a C++ project to a DLL for other C++ projects to use. When building the DLL, as you may assume I want all compiled header objects from the project to be linked into the DLL build. However, I don't want all those headers to be accessible to users of the DLL.
For example, let's say some DLL project has the following headers:
FORFRUITSONLY.h
orange.h
apple.h
orange.h and apple.h both #include FORFRUITSONLY.h or else they wouldn't function. However, I want users of this DLL to only be able to #include orange.h and/or apple.h with the desire for the compiler to fail if they try to #include FORFRUITSONLY.h. How can I achieve this?
#include "FORFRUITSONLY.h"? Even if you accomplish this, they could simply instead#include "apple.h"and thereby access everything they could if they were to include the forbidden file directly (inclusion is transitive). There are ways to prevent direct inclusion, but I suspect they would not help you meet your real goal. (PIMPL might.)#includeing FORFRUITSONLY.h in orange.h and apple.h and only include it in orange.cpp and apple.cpp. That way you don't need to ship FORFRUITSONLY.h with your library and thus consumers can't#includeit.