How can I get the compiler to tell me which file #define value?

My code links to several other libraries that are also being developed in my company, one of these libraries overrides several values ​​from errno.h, I would like to be able to fix it, however, I had problems finding the exact file that overrides these values, I want to know if there is a way to get the compiler to tell me when the file specified a specific value.

+3
source share
6 answers

Perhaps you can do this by adding -include errno.hto the command line, which creates the appropriate library. Here is a brief example. I have a C program called "file.c":

#define ESRCH 8

What is it - then I will compile with:

cc -c -include errno.h file.c

And presto, compiler warning:

file.c:1:1: warning: "ESRCH" redefined
In file included from /usr/include/errno.h:23,
                 from <command-line>:0:
/usr/include/sys/errno.h:84:1: warning: this is the location of the previous definition

This will tell you where your bad definitions are.

+5
source

Have you tried searching using grep?

+3
source

#define,

#undef YOUR_MANIFEST_CONSTANT

#include , , .

, , #define . .

+2

GCC - :

g++ input.cc -dD -E > cpp.out

-dD cpp , . cpp .

+2

, , , IDE, , " ", . , , .

, , , . , grep/findstr on * nix/Windows - . , .

0

IDE , " ".

, , - . , ++. ( , ++). , , , .

0

Source: https://habr.com/ru/post/1751636/


All Articles