I have a C++ code which depends on libuv library (C code). It’s crashing because of the segfault. I narrowed down the problem: libuv uses struct stat from <sys/stat.h>. If I print size of this struct in my code:
printf("struct stat size: %d\n", sizeof(struct stat));
it shows 88. If I print the same in libuv library, it shows 96. This is the cause of the segfault. I am a bit stuck here. How can I find exact location of type declaration? Any other approach to solve this problem?
You could preprocess the source with
cc -E xxx.c, and look for the offending definition in there. The#fileand#linedirectives in the preprocessedxxx.iwill point you to the approximate position of the culprit. Or just#include <sys/stat.h>at the very beginning (before any stuff from the library), the compiler should scream at you for redefining thestruct😉