Reputation: 2019
I have a c program kept at different directories 'source1/abc.c' and 'source2/abc.c'. I want to generate the object code in 'object1/abc.o' and 'object2/abc.o'. Both abc.c program in source1 and source2 directory are same. But after compilation both the objects( i.e. abc.o ) of object1 and object2 are of different size. I am taking same flag for compilation.
I tries compiling the code from some other directory, other than object1 and object2 and the size after compilation are same.
cc -c source1/abc.c -DLINUX -D_LARGE_THREADS -D_THREAD_SAFE -D_REENTRANT -pthread -D_GNU_SOURCE -g -fPIC -O3 -lpthread -lm -lrt -o object1/abc.o
cc -c source2/abc.c -DLINUX -D_LARGE_THREADS -D_THREAD_SAFE -D_REENTRANT -pthread -D_GNU_SOURCE -g -fPIC -O3 -lpthread -lm -lrt -o object2/abc.o
The size of abc.o should be equal or does it depend on the directories from which it is running? What are the dependencies while compilation of c program?
Upvotes: 4
Views: 118
Reputation: 84
You're compiling with -g option, which adds debug Information to the object file. These might contain path Information of the source files, so different paths lead to different symbols and a different total file size.
Upvotes: 5