why code show error
error: ld returned 1 exit status
Code:#include <stdio.h>
void myFunction() {
#ifdef DEBUG
printf("Debugging mode is on.\n");
#endif
}
int main() {
myFunction();
return 0;
}
Printable View
why code show error
error: ld returned 1 exit status
Code:#include <stdio.h>
void myFunction() {
#ifdef DEBUG
printf("Debugging mode is on.\n");
#endif
}
int main() {
myFunction();
return 0;
}
Maybe post your actual linker error message, because there's nothing obvious from the code so far.
This is a simple C program that defines a function myFunction() and calls it from main(). The function myFunction() contains a preprocessordirective #ifdef that checksif the DEBUG macro has beendefined. If it has, the function prints the message "Debugging mode ison." to the console using printf(). . If it is not defined, the message will not be printed.
I don't understand what would be benefit of checking define macroCode:#define DEBUG#include <stdio.h>
void myFunction() {
#ifdef DEBUG
printf("Debugging mode is on.\n");
#endif
}
int main() {
myFunction();
return 0;
}
And what exactly does that have to do with linker error messages.
It's a completely different question.
> My main question was what would be benefit of checking define macro as shown in code ?
The code you compile for yourself:
gcc -DDEBUG prog.c
It contains diagnostic information that you find useful for general debugging and knowing that things are as they should be.
You wouldn't have "#define DEBUG" in the code, you'd control it from the command line as shown.
The code you compile to give to other people:
gcc -O2 prog.c
End users don't care about what you see, they just want a program that does what it says.