Strange Compiler Error: “undefined reference to 'main'”

守給你的承諾、 提交于 2019-12-01 18:24:20

That first rule should be

program : main.o render.o screenwriter.o
    g++ -o program main.o render.o screenwriter.o -lSDL

Assuming that you want to link main.o render.o screenwriter.o into an executable called program

Also, in the compile steps ( -c ) the -lDSL bit is not useful, it's a linker instruction.

Change the second line to:

g++ -o program main.o render.o screenwriter.o -lSDL
       ^^^^^^^

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:

$(CXX) -o $@ $+ -lSDL

So even when you expand your program, you won't have to edit that command again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!