dav
dav

Reputation: 936

Why aren't my variables expanding in my makefile?

I'm using mingw32-make to run my makefile. The contents of the Makefile are the following:

#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 $@ 

^(the white-space before the commands are tabs)^

When run, the shell outputs

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

which indicates that the other variables are not being expanding in the first pattern rule. Oddly, only CC is expanding into g++. Why is this happening?

Upvotes: 1

Views: 53

Answers (1)

Joseph Quinsey
Joseph Quinsey

Reputation: 9952

The issue is not one of non-expanding variables. Rather, the makefile is using the default rule instead of the one you provided.

The reason may be that your rule uses *.c, while you likely have *.cpp files, IIRC.

Upvotes: 1

Related Questions