为什么我的变量没有在我的Makefile中扩展?

时间:2018-08-10 02:55:52

标签: makefile mingw gnu-make

我正在使用mingw32-make运行我的Makefile。 Makefile的内容如下:

#OBJS specifies which files to compile as part of the project 
OBJS = SDLpp.o SDLpp_exception.o SDLpp_window.o

#CC specifies which compiler we're using 
CC = g++ 

#INCLUDE_PATHS specifies the additional include paths we'll need 
INCLUDE_PATHS = -IC:\mingw_dev_lib\include\SDL2 \
                -IC:\mingw_dev_lib\include\SDL_image \
                -IC:\mingw_dev_lib\include\SDLpp

#LIBRARY_PATHS specifies the additional library paths we'll need 
LIBRARY_PATHS = -LC:\mingw_dev_lib\lib

#COMPILER_FLAGS specifies the additional compilation options we're using 
# -w suppresses all warnings 
# -Wall includes all warnings
# -Wl,-subsystem,windows gets rid of the console window 
COMPILER_FLAGS = -Wall

#LINKER_FLAGS specifies the libraries we're linking against 
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

#LIB_NAME specifies the name of our library 
LIB_NAME = libSDLcpp.a

#This is the target that compiles our executable 

all : $(OBJS)
    ar rvs $(LIB_NAME) $(OBJS)

%.o : %.c
    $(CC) $< $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) -c $(LINKER_FLAGS) -o $@ 

^(命令前的空白是制表符)^

运行时,shell输出

g++ -c -o SDLpp.o SDLpp.cpp

表示其他变量未在第一个模式规则中扩展。奇怪的是,只有CC扩展为g++。为什么会这样?

1 个答案:

答案 0 :(得分:1)

问题不是非扩展变量之一。相反,makefile使用的是默认规则,而不是您提供的默认规则。

原因可能是您的规则使用*.c,而您可能拥有*.cpp文件,即IIRC。