C Linking Error: undefined reference to ‘main’


I have read the other answers on this topic, and unfortunately they have not helped me. I am attempting to link several c programs together, and I am getting an error in response:

$ gcc -o runexp.o scd.o data_proc.o -lm -fopenmp
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: * [runexp] Error 1

I have exactly one main function and it is in runexp. The form is

int main(void) {
    return 0;

Any thoughts on why I might get this error? Thanks!


You should provide output file name after -o option. In your case runexp.o is treated as output file name, not input object file and thus your main function is undefined.

Source: StackOverflow.com

Leave a Reply

Your email address will not be published. Required fields are marked *