函数`_start':init.c :(.text + 0x30):对'main'的未定义引用

Hag*_*ble 4 c linker undefined-reference

我正在开发一个包含大约30个源文件(.c)的C项目.我正在使用GNU工具在Ubuntu上运行的32位微控制器(i.MX515)上构建这个项目.

编译阶段成功完成,但是当链接过程开始时,我收到此错误(对于问题结尾处的完整错误):

In function `_start': init.c:(.text+0x30): undefined reference to `main'
Run Code Online (Sandbox Code Playgroud)

我有main()一个简单的功能printf().

我的Makefile链接,看起来像这样.

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)
Run Code Online (Sandbox Code Playgroud)

救命!!!

问候

维克拉姆


完成链接错误

/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
Run Code Online (Sandbox Code Playgroud)

Kev*_*imm 8

final取决于main.o(以及其他一些),但是,你的makefile正在接受所有'其他'并在main.o中输出它们(这是大多数编译器中的-o所做的)

编辑您的链接行: -o final $(OBJDIR)/main.o