简体   繁体   English

如何设置这个makefile

[英]how to set this makefile

I have makefile with two source files namely main.cpp and game.cpp . 我有带有两个源文件的makefile,即main.cppgame.cpp Once I add game.cpp , I'm getting the following warning 添加game.cpp ,我将收到以下警告

clang++ -framework SDL2 main.o -o game
Undefined symbols for architecture x86_64:

And this is the makefile 这是makefile

CXX      = clang++
SDL      = -framework SDL2
CXXFLAGS = -Wall -c -std-c++11
LDFLAGS  = $(SDL)
TARGET   = game

all: $(TARGET)

$(TARGET): main.o game.o
    $(CXX) $(LDFLAGS) $< -o $@

main.o: main.cpp
    $(CXX) $(CXXFLAGS) $< -o $@

game.o: game.cpp
    $(CXX) $(CXXFLAGS) $< -o $@

clean:
    rm *.o && rm $(TARGET)

I'm using Mac. 我正在使用Mac。

You are missing game.o in the build command, this is because $< is only the first dependency (see the first line in your warning). 您在build命令中缺少game.o ,这是因为$<只是第一个依赖项(请参阅警告的第一行)。 Hence the functions in game.o are undefined. 因此game.o中的函数未定义。

For more info please refer to gnu.org 有关更多信息,请访问gnu.org

EDIT: Updated the link as suggested 编辑:根据建议更新了链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM