Tag Archives: Scientific research tools

GCC Error:(.text+0x24): undefined reference to `main‘collect2: error: ld returned 1 exit status [Solved]

I can’t remember why I solved it like this. I searched again and didn’t find a similar answer.

Due to the needs of the experiment, I need to compile this example:

https://github.com/grimm-co/GEARSHIFT/blob/trunk/examples/simple.c

However, if you run directly:

gcc simple.c -O0 -o simple

otherwise will report an error:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: in function `_start’:
(.text+0x24): undefined reference to `main’
collect2: error: ld returned 1 exit statu

Solution:

Change to

gcc -shared simple.c -O0 -o simple

Just. I suddenly remembered how I solved it. I referred to this: https://github.com/grimm-co/GEARSHIFT/blob/trunk/examples/Makefile

The online solutions are different from this, so here’s a simple record. It’s hard to say that it can help other basin friends.