I'm trying to force ValGrind to tell me what's wrong with my program. Every shred of documentation on the face of the Internet says that you must supply the -g
option to GCC, but not one single document says whether you need this flag at compile-time or link-time (or both). So which is it??
The GNU ld documentation says that -g
will be ignored, so it doesn't make much sense to pass it. In general you pass -g
to gcc
(which really is a front-end for the whole compilation process and not just a compiler) and it will take care of it.
GCC provides -g flag to get the debugging, So one you compile the program like Consider a code of example.c like:
#include <stdio.h>
/* Warning: This program is wrong on purpose. */
int main()
{
int age = 10;
int height;
printf("I am %d years old.\n");
printf("I am %d inches tall.\n", height);
return 0;
}
By default if you compile say using make example
It will trigger command
cc example.c -o example
Now you run command like
cc -g example.c -o example1
then you will find the size of the file example1
is greater than the size of example
because -g flag enabled the debugging information.
While running valgrind is -g flag is not required. -g is only required in compilation process.
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.