是否有一种方法可以修改INCLUDE
中框架的Makefile
路径,以便像Windows一样将<SDL2/SDL.h>
简化为<SDL.h>
?
除了现有的Windows库之外,我正在尝试编辑团队的Makefile,以便为Mac的本机形式的库,框架提供跨平台支持,以便我们可以使代码尽可能简单。
我知道#ifdef __APPLE_CC__
用于包装Mac专用代码,但是分别包装<SDL2/SDL.h>
和<SDL.h>
的每个实例似乎是多余的。
#include <SDL.h>
#include <SDL_image.h>
#include <SDL2/SDL.h>
#include <SDL2_Image/SDL_image.h>
# Windows part
ifeq ($(OS), Windows_NT)
DETECTED_OS = $(OS)
CC = g++ -std=c++11
CFLAGS = -c -IC:/mingwdev/include/SDL2
INCLUDE = -IC:/mingwdev/include/SDL2
LFLAGS = -LC:/mingwdev/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -o $(OUT)
LFLAGScr = -LC:/mingwdev/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
# Mac part
else ifeq ($(shell uname -s), Darwin)
DETECTED_OS := $(shell uname -s)
CC = g++ -std=c++11
CFLAGS = -c -F/Library/Frameworks # THIS IS WHAT I WANT TO MODIFY #
INCLUDE = -F/Library/Frameworks # THIS IS WHAT I WANT TO MODIFY #
LFLAGS = -framework SDL2 -framework SDL2_image -framework SDL2_ttf -o $(OUT)
LFLAGScr = -framework SDL2 -framework SDL2_image -framework SDL2_ttf
# Final Part
all: $(OUT)
$(OUT): $(OBJ)
$(CC) $^ $(INCLUDE) $(LFLAGS)
obj/%.o: src/%.cpp $(DEP)
$(CC) $< $(CFLAGS) -o $@
答案 0 :(得分:0)
要像Windows一样使用#include <SDL.h>
,除了让编译器知道它正在使用带有以下内容的框架外,还需要使用-I
命令提供框架内标头的路径。 -F
。
Makefile中的两行如下所示:
CFLAGS = -c -I/Library/Frameworks/SDL2.framework/Headers -F/Library/Frameworks/
INCLUDE = -I/Library/Frameworks/SDL2.framework/Headers -F/Library/Frameworks/
要包含第二个库(例如SDL_image),只需执行以下操作:
CFLAGS = -c -I/Library/Frameworks/SDL2.framework/Headers -I/Library/Frameworks/SDL2_image.framework/Headers -F/Library/Frameworks/
INCLUDE = -I/Library/Frameworks/SDL2.framework/Headers -I/Library/Frameworks/SDL2_image.framework/Headers -F/Library/Frameworks/
(不客气,我本人和社区。)