0

When I run "g++ -Wall programName.cpp" the compiler outputs warnings about unused variables, but when I use the Makefile to compile, these warnings do not appear. I have the

OBJS = test.o

# Name of executable
NAME = ../test

# Flags to pass to the compiler. 
CFLAGS = -Wall

all: $(NAME)

$(NAME): $(OBJS)
   g++ $(CFLAGS) -o $(NAME) $(OBJS)

in my Makefile, but doesn't seem to work. Does anyone know what could be causing this???

When I run the make I get the output:

 g++    -c -o test.o test.cpp
 g++ -Wall -o test test.o

It seems like the -Wall is only being applied to the process of turning the .o file into an executable, not the part of .cpp -> .o

tripleee
  • 175,061
  • 34
  • 275
  • 318
user2494298
  • 299
  • 3
  • 7
  • 23

2 Answers2

1

The variable is named CFLAGS, not CLAGS.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Was a typo when entering the question...sorry. I had CFLAGS – user2494298 Sep 19 '13 at 15:32
  • Then, there's absolutely nothing we can do to help you with the information you've provided. That statement will set CFLAGS to that value. Great. So obviously if you're not seeing that flag on your compile line, then the problem is somewhere else in your makefile. – MadScientist Sep 19 '13 at 15:41
1

You are overriding the built-in rule for going from OBJS to NAME, but not the rule for compling .cpp to.o.

The proper fix would appear to be to not override any built-in rules, and instead adding -Wall to the correct flags variable for the built-in rules (I guess in this case CXXFLAGS). See also Difference between CPPFLAGS and CXXFLAGS in GNU Make

Community
  • 1
  • 1
tripleee
  • 175,061
  • 34
  • 275
  • 318