C语言 在函数“_start”中:init.c:(.text+0x30):对“main”的未定义引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2758088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:21:19  来源:igfitidea点击:

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

clinkerundefined-reference

提问by HaggarTheHorrible

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.

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

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().

我有一个main()函数可以做一个简单的printf().

My Makefile line for linking, looks like this.

我用于链接的 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)

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

回答by KevinDTimm

finaldepends 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)

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

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

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

回答by RdM

The linker cannot find the object code for the source that has main() defined in it. Probably its not getting compiled. Check that whichever of the 30 files it is that has main() in it, is getting compiled to .OBJ.

链接器找不到其中定义了 main() 的源的目标代码。可能它没有被编译。检查其中包含 main() 的 30 个文件中的任何一个是否被编译为 .OBJ。