奇怪的编译器错误:“未定义对‘main’的引用”
有人能告诉我这是什么意思吗?
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [program] Error 1
我的 make 文件如下所示:
program : main.o render.o screenwriter.o
g++ -o main.o render.o screenwriter.o -lSDL
main.o : main.cpp render.h screenwriter.h
g++ -c main.cpp render.h screenwriter.h -lSDL
render.o : render.h render.cpp
g++ -c render.h render.cpp -lSDL
screenwriter.o : screenwriter.h screenwriter.cpp
g++ -c screenwriter.h screenwriter.cpp -lSDL
clean:
rm program main.o render.o screenwriter.o -lSDL
谢谢。
Could someone tell me what this means?
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [program] Error 1
My make file looks like as follows:
program : main.o render.o screenwriter.o
g++ -o main.o render.o screenwriter.o -lSDL
main.o : main.cpp render.h screenwriter.h
g++ -c main.cpp render.h screenwriter.h -lSDL
render.o : render.h render.cpp
g++ -c render.h render.cpp -lSDL
screenwriter.o : screenwriter.h screenwriter.cpp
g++ -c screenwriter.h screenwriter.cpp -lSDL
clean:
rm program main.o render.o screenwriter.o -lSDL
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一条规则应该是
假设您想要将
main.o render.o screenwriter.o
链接到名为program
的可执行文件中。此外,在编译步骤 ( -c ) 中
-lDSL
位没有用,它是链接器指令。That first rule should be
Assuming that you want to link
main.o render.o screenwriter.o
into an executable calledprogram
Also, in the compile steps ( -c ) the
-lDSL
bit is not useful, it's a linker instruction.将第二行更改为:
否则,您的输出是main.o,并且您在输入中丢失了它。
比手动维护牺牲更好的是使用特殊宏:
因此,即使您扩展程序,您也不必再次编辑该命令。
Change the second line to:
Otherwise your output is main.o and you're missing it in the input.
Even better than manual maintenance martyrdom is to use special macros:
So even when you expand your program, you won't have to edit that command again.