Reputation: 9415
In my case, I have two layers say core layer and application layer. Application layer depends of core layer.
I want that only core layer should use CRT functions.
In application layer, if any CRT function is used, it should not compile.
Is there any way to achieve this? For example, direct call to free/malloc should not be made in application layer.
One way which I thought to #define all CRT functions to some error so that Application layer cannot use direct CRT calls (Application layer is including the header files of core layer).
Upvotes: 3
Views: 2058
Reputation: 18358
You don't need to #define all the funcs in CRT. It's enough to define one of the funcs declared in the header to cause compilation failure.
Also, look into the CRT headers, most of them rely on some construct of this kind:
#ifndef "some unique id"
#define "some unique id"
/* header body */
#endif
If you define this unique id, you'll effectively cause the header not to be included, thus compilation error will occur when trying to use function declared in this header.
Upvotes: 1
Reputation: 7309
Assuming all your projects are native C or C++, I believe removing the references to the windows CRT binaries should suffice. If anyone tries to use them, they'll get link errors.
For a dll, open the project properties (from Visual Studio), then go to Configuration Properties->Linker->Input
and set Ignore All Default Libraries
to Yes (/NODEFAULTLIB)
. Right above that one, set Additional Dependencies
to just the libraries from your solution that you need.
For a static library, go to Librarian->General
and do the same.
Upvotes: 1