I'm just starting with C. I'm trying to compile the below code and execute it, but I get an error.
Also running size
shows nothing in BS or data stacks?
#include<stdio.h>
/* test.c: My first C program on a Linux */
int main(void)
{
printf("Hello! This is a test prgoram.\n");
return 0;
}
Compiling works:
gcc -c test.c -o test
Executing:
bash: ./test: cannot execute binary file: Exec format error
Size:
text data bss dec hex filename
108 0 0 108 6c test
Ok since no one wants wanted to say why... you need to remove the -c option because according to the man:
the -c option says not to run the linker. Then the output consists of object files output by the assembler.
So basically, you are not creating a fully executable file, just object files.
Here's some quick info on how compiling works: http://courses.cms.caltech.edu/cs11/material/c/mike/misc/compiling_c.html
The -c
flag is not correct in this case:
gcc test.c -o test
-c This option is used to compile the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With