Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In function `_start': init.c:(.text+0x30): undefined reference to `main'

I'm working on a C project with around 30 source files (.c). I'm building this project on a 32 bit micro-controller(i.MX515) running on Ubuntu using GNU tools.

The compilation phase completes successfully, however when the linking process starts I get this error (For full error at the end of the quesiton):

In function `_start': init.c:(.text+0x30): undefined reference to `main'

I have a main() function which does a simple printf().

My Makefile line for linking, looks like this.

final: $(OBJDIR)/main.o $(OBJDIR)/TchClaKnn_BuildKdtreeInt.o $(OBJDIR)/TchClaKnn_FreeKdtreeInt.o.... (Go upto 30 files like this)
    @echo ".Linking"
    $(CC) $(LFLAGS) -o $(OBJDIR)/main.o $(OBJDIR)/TchClaKnn_BuildKdtreeInt.o $(OBJDIR)/TchClaKnn_FreeKdtreeInt.o..... (Go upto 30 files like this)

Help!!!

Regards

Vikram


Complete linking error

/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o: In function `_start':
init.c:(.text+0x30): undefined reference to `main'
collect2: ld returned 1 exit status
make[1]: *** [final] Error 1
make[1]: Leaving directory `/home/ubuntu/Documents/Project/IMX_Project_v1'
make: *** [all] Error 2
like image 878
HaggarTheHorrible Avatar asked May 03 '10 12:05

HaggarTheHorrible


People also ask

How do you fix undefined references to Main in C?

To fix this error, correct the spelling of the main() function.

What does undefined reference to main mean in C?

Undefined reference to main could mean that you haven't defined one of the functions in your class or something of that nature. blog2562099974 April 20, 2022, 2:33am #3. #include <iostream> int main() { std::cout << "texthere\n"; }

What is undefined reference?

An “Undefined Reference” error occurs when we have a reference to object name (class, function, variable, etc.) in our program and the linker cannot find its definition when it tries to search for it in all the linked object files and libraries.

What is __ Dso_handle?

__dso_handle is a "guard" that is used to identify dynamic shared objects during global destruction.


1 Answers

final depends on main.o (and a bunch of others), but, your makefile is taking all the 'others' and outputting them in main.o (that's what -o does in most compilers)

edit your link line to : -o final $(OBJDIR)/main.o

like image 131
KevinDTimm Avatar answered Nov 15 '22 06:11

KevinDTimm