I have this code
#include <stdio.h>
void test2()
{
printf("start test2\n");
printf("end test2\n");
}
void main ()
{
printf("abc\n");
#ifdef A
test2();
#endif
}
compile it with gcc test.c -o test -static -D B
when I run the program I see that test2
didn't run (that good)
But when I run strings I can see that end test2
in binary file. why? gcc didn't need to compile it !
When I compile this code
#include <stdio.h>
void test1();
void test2()
{
printf("start test2\n");
test1();
printf("end test2\n");
}
void main ()
{
printf("abc\n");
#ifdef A
test2();
#endif
}
with gcc test.c -o test -static -D B
Gcc tell me that undefined reference to 'test1'
why? I didn't want that gcc even compile function test2
so gcc didn't need to know that I used that undefined function.
What can I do that gcc will not look on test2
when I pass -D
that not equal to A
?