首页 > 解决方案 > 为什么我的变量没有在我的 makefile 中扩展?

问题描述

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++. 为什么会这样?

标签: makefilemingwgnu-make

解决方案


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

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


推荐阅读