If I want gcc compiler to throw an error if I include stdlib.h
or a particular header, what flags should I use?. I don't want to use -nostdlib
flag, because it doesn't link any standard libraries.
For each header file there is an include guard, so I guess you can try to check for it like this
#ifdef _STDLIB_H
#error "You should not include stdlib.h"
#endif
and then you can apply the same with other headers. Of course, this will only work with a particular c
standard library in this case I took the include guard from stdlib.h
in glibc . And it will not work if you include stdlib.h
after checking.
Also, a header file is not a library, it contains definitions and functions prototypes from libraries, if you don't want you program to link to the standard library you have no other option AFAIK than gcc -nostdlib
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.